Use the correct ClassLoader in createFromParcel for lists#356
Conversation
…ndException when unmarshalling` Error Parcelable codes
FIX #354 `android.os.BadParcelableException: ClassNotFoundException …
|
Thanks for this change. It's nice to have someone trying the parcelable support and reporting back these improvements. |
|
I ran into the same Parcelable error, and used a workaround to fix it so I was happy to see a fix for this. For a field of in.readList(instance.ranges, (java.lang.Long>.class.getClassLoader())); |
|
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 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]);
}
}
; |
…when unmarshalling` Error Parcelable codes
Sorry for no testcase, I can't make original testcase pass in my mac.