Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the correct ClassLoader in createFromParcel for lists #356

Merged

Conversation

simpleton
Copy link
Contributor

…when unmarshalling` Error Parcelable codes

Sorry for no testcase, I can't make original testcase pass in my mac.

…ndException when unmarshalling` Error Parcelable codes
joelittlejohn added a commit that referenced this pull request May 15, 2015
FIX #354  `android.os.BadParcelableException: ClassNotFoundException …
@joelittlejohn joelittlejohn merged commit f062aef into joelittlejohn:master May 15, 2015
@joelittlejohn joelittlejohn added this to the 0.4.12 milestone May 15, 2015
@joelittlejohn joelittlejohn changed the title FIX #354 `android.os.BadParcelableException: ClassNotFoundException … Fix android.os.BadParcelableException: ClassNotFoundException when parceling lists May 15, 2015
@joelittlejohn
Copy link
Owner

Thanks for this change. It's nice to have someone trying the parcelable support and reporting back these improvements.

@simpleton simpleton deleted the bug/array_in_parcelable branch May 16, 2015 07:18
@joelittlejohn joelittlejohn changed the title Fix android.os.BadParcelableException: ClassNotFoundException when parceling lists Fix Class loading problem when parceling lists May 28, 2015
@joelittlejohn joelittlejohn changed the title Fix Class loading problem when parceling lists Use the correct ClassLoader in createFromParcel for lists May 28, 2015
@yomik
Copy link
Contributor

yomik commented Jun 30, 2015

I ran into the same Parcelable error, and used a workaround to fix it so I was happy to see a fix for this.
Unfortunately, this creates a whole new set of issues when using nested lists (e.g. List<List<Long>>), since the generated model does not compile anymore !

For a field of List<List<Long>>, the generated code is

in.readList(instance.ranges, (java.lang.Long>.class.getClassLoader()));

@simpleton
Copy link
Contributor Author

Could you show me some code snippet which generate the wrong source code?

On Tue, Jun 30, 2015 at 3:08 PM, Y. M. notifications@github.com wrote:

I ran into the same Parcelable error, and used a workaround to fix it so I
was happy to see a fix for this.
Unfortunately, this creates a whole new set of issues when using nested
lists (e.g. List>), since the generated model does not compile anymore !

For a field of List>, the generated code is

in.readList(instance.ranges, (java.lang.Long>.class.getClassLoader()));


Reply to this email directly or view it on GitHub
#356 (comment)
.

@yomik
Copy link
Contributor

yomik commented Jul 1, 2015

I used this sample json (extracted from my actual json file) :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "valid_time_ranges_by_date": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/valid_range_in_specific_date"
      }
    }
  },
  "required": ["valid_time_ranges_by_date"],
  "definitions": {
    "valid_range_in_specific_date": {
      "type": "object",
      "properties": {
        "date": {
          "title": "Date (YYYY-MM-DD).",
          "type": "string",
          "format": "date"
        },
        "ranges": {
          "title": "Defines valid time ranges in one day. Array of pair [start,end].",
          "type": "array",
          "items": {
            "title": "Constraints start < end, start >= 0, end <= 86400000",
            "minItems": 2,
            "maxItems": 2,
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 86400000
            }
          }
        },
        "required": ["date", "ranges"]
      }
    }
  }
}

Which produced two java files : Test.java looks correct, ValidTimeRangesByDate.java is not. This is what the CREATOR looks like :

    public final static Parcelable.Creator<ValidTimeRangesByDate> CREATOR = new Creator<ValidTimeRangesByDate>() {


        public ValidTimeRangesByDate createFromParcel(Parcel in) {
            ValidTimeRangesByDate instance = new ValidTimeRangesByDate();
            instance.date = ((String) in.readValue((String.class.getClassLoader())));
            in.readList(instance.ranges, (java.lang.Long>.class.getClassLoader()));
            instance.required = ((Object) in.readValue((Object.class.getClassLoader())));
            instance.additionalProperties = ((Map<String, Object> ) in.readValue((Map.class.getClassLoader())));
            return instance;
        }

        public ValidTimeRangesByDate[] newArray(int size) {
            return (new ValidTimeRangesByDate[size]);
        }

    }
    ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants