-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
RuntimeTypeAdapterFactory<Base> with JsonDeserializer<Derived> is unsupported #1570
Comments
I am seeing the same issue, does anyone know a solution? |
I didn't find any solution except for making my own copy of RuntimeTypeAdapterFactory.java and patching the code like this:
|
|
This issue unfortunately still exists, even with #1787 being merged. For backward compatibility this specific case was not fixed, see #1787 (comment). As workaround for the specific case described in this issue it might be possible to use |
Hi,
I want the RuntimeTypeAdapterFactory to differentiate between the derived class types and then deserialize the derived instance using a JsonDeserializer.
However, if I register RuntimeTypeAdapterFactory and JsonDeserializer, Gson does not serialize the derived class using the RuntimeTypeAdapterFactory.
Minimal not working example:
The toJson returns
{"bases":[{},{"type":"Derived2"}]}
instead of:
{"bases":[{"type":"Derived1"},{"type":"Derived2"}]}
and of course fromJson fails afterwards with "JsonParseException: cannot deserialize class Base because it does not define a field named type".
TIA,
Dror
The text was updated successfully, but these errors were encountered: