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
@SuppressWarnings({"rawtypes", "unchecked"}) @OverRide
public void write(JsonWriter out, T value) throws IOException {
...
if (runtimeType != type) {
TypeAdapter runtimeTypeAdapter = context.getAdapter(TypeToken.get(runtimeType));
if (!(runtimeTypeAdapter instanceof ReflectiveTypeAdapterFactory.Adapter)) {
// The user registered a type adapter for the runtime type, so we will use that
chosen = runtimeTypeAdapter;
} else if (!(delegate instanceof ReflectiveTypeAdapterFactory.Adapter)) {
// The user registered a type adapter for Base class, so we prefer it over the
// reflective type adapter for the runtime type
chosen = delegate;
} else {
...
}
I created a Gson instance using GsonBuilder which registered a JsonDeserializer for type BaseQuestion.
And there is a class Form has a field of List holding BaseQuestion's instances ( i.g ScoreQuestion extends BaseQuestion ).
When I trying to serialize Form by using gson.toJson(form), I found that variable delegate was used as variable chosen but it was just a JsonDeserializer. It leads ScoreQuestion declare fields missed.
Should variable delegate distinguish by read or write operation ? For example , readDelegate ,writeDelegate, not just a TreeTypeAdapter.
The text was updated successfully, but these errors were encountered:
82295007
changed the title
should
DeSerializerAdapter lead field missing while serializing
Aug 1, 2018
I am going to close this because no answer has been provided. If you still experience this with the latest Gson version, feel free to comment here again with more details.
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper#write
@SuppressWarnings({"rawtypes", "unchecked"})
@OverRide
public void write(JsonWriter out, T value) throws IOException {
...
if (runtimeType != type) {
TypeAdapter runtimeTypeAdapter = context.getAdapter(TypeToken.get(runtimeType));
if (!(runtimeTypeAdapter instanceof ReflectiveTypeAdapterFactory.Adapter)) {
// The user registered a type adapter for the runtime type, so we will use that
chosen = runtimeTypeAdapter;
} else if (!(delegate instanceof ReflectiveTypeAdapterFactory.Adapter)) {
// The user registered a type adapter for Base class, so we prefer it over the
// reflective type adapter for the runtime type
chosen = delegate;
} else {
...
}
I created a Gson instance using GsonBuilder which registered a JsonDeserializer for type BaseQuestion.
And there is a class Form has a field of List holding BaseQuestion's instances ( i.g ScoreQuestion extends BaseQuestion ).
When I trying to serialize Form by using gson.toJson(form), I found that variable delegate was used as variable chosen but it was just a JsonDeserializer. It leads ScoreQuestion declare fields missed.
Should variable delegate distinguish by read or write operation ? For example , readDelegate ,writeDelegate, not just a TreeTypeAdapter.
The text was updated successfully, but these errors were encountered: