You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"foo"
})
public class A implements Parcelable
{
@JsonProperty("foo")
private String foo;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public final static Parcelable.Creator<A> CREATOR = new Creator<A>() {
@SuppressWarnings({
"unchecked"
})
public A createFromParcel(Parcel in) {
A instance = new A();
instance.foo = ((String) in.readValue((String.class.getClassLoader())));
instance.additionalProperties = ((Map<String, Object> ) in.readValue((Map.class.getClassLoader())));
return instance;
}
public A[] newArray(int size) {
return (new A[size]);
}
}
;
/**
*
* @return
* The foo
*/
@JsonProperty("foo")
public String getFoo() {
return foo;
}
/**
*
* @param foo
* The foo
*/
@JsonProperty("foo")
public void setFoo(String foo) {
this.foo = foo;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(foo);
dest.writeValue(additionalProperties);
}
public int describeContents() {
return 0;
}
}
and B.java
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"bar"
})
public class B
extends A
implements Parcelable
{
@JsonProperty("bar")
private long bar;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public final static Parcelable.Creator<B> CREATOR = new Creator<B>() {
@SuppressWarnings({
"unchecked"
})
public B createFromParcel(Parcel in) {
B instance = new B();
instance.bar = ((long) in.readValue((long.class.getClassLoader())));
instance.additionalProperties = ((Map<String, Object> ) in.readValue((Map.class.getClassLoader())));
return instance;
}
public B[] newArray(int size) {
return (new B[size]);
}
}
;
/**
*
* @return
* The bar
*/
@JsonProperty("bar")
public long getBar() {
return bar;
}
/**
*
* @param bar
* The bar
*/
@JsonProperty("bar")
public void setBar(long bar) {
this.bar = bar;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(bar);
dest.writeValue(additionalProperties);
}
public int describeContents() {
return 0;
}
}
which means that when trying to Parcelable a B instance, the information contained in A is lost in the process since writeToParcel does not call its parent, neither does createFromParcel read the superclass values.
For such cases, I currently need to create a dummy A object filled in with B info, then marshalling my dummy A then B. Unmarshalling is the opposite process, with unmarshalling of A then B, then put back the properties from A into B.
It would be nice if the generated Parcelable code could handle inherited classes, though it doesn't look like and easy task
The text was updated successfully, but these errors were encountered:
yomik
added a commit
to yomik/jsonschema2pojo
that referenced
this issue
Jun 1, 2017
With the following sample json files :
a.json :
and b.json :
The generated classes will look like :
A.java
and B.java
which means that when trying to Parcelable a B instance, the information contained in A is lost in the process since writeToParcel does not call its parent, neither does createFromParcel read the superclass values.
For such cases, I currently need to create a dummy A object filled in with B info, then marshalling my dummy A then B. Unmarshalling is the opposite process, with unmarshalling of A then B, then put back the properties from A into B.
It would be nice if the generated Parcelable code could handle inherited classes, though it doesn't look like and easy task
The text was updated successfully, but these errors were encountered: