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

DeSerializerAdapter lead field missing while serializing #1365

Closed
82295007 opened this issue Aug 1, 2018 · 2 comments
Closed

DeSerializerAdapter lead field missing while serializing #1365

82295007 opened this issue Aug 1, 2018 · 2 comments

Comments

@82295007
Copy link

82295007 commented Aug 1, 2018

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.

@82295007 82295007 changed the title should DeSerializerAdapter lead field missing while serializing Aug 1, 2018
@Marcono1234
Copy link
Collaborator

Does #2032 describe your issue? If not, and this is still relevant, could you please create a small self-contained sample showing this?

@Marcono1234
Copy link
Collaborator

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.

@Marcono1234 Marcono1234 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants