-
Notifications
You must be signed in to change notification settings - Fork 81
jClass annotations and polymorphic types are ignored when deserializing Android Record fields #248
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
Comments
Hi @HelloOO7, thanks for reporting this. I would appreciate a PR with a fix, and I'll gladly review it (though I can't approve). If you could, please check if it fixes any tests in the |
On an unrelated note, out of curiosity, any reason why, in your sample class hierarchy, |
Would be interesting to have a test for regular Java SDK Records with similar set up (for jackson-databind). I assume that should work but I am not sure this is covered. |
In this specific sample, no. In some of my real use cases, however, I use member inheritance for fields and base methods, which, although mostly substitutable through interface default methods, I find preferable to using records.
In this case, the problem was that the ValueInstantiator that was being used simply never resolved the actual polymorphic type, which, in standard Jackson deserialization flow, should most likely not happen.
I would also like to correct myself on this statement - it appears that type annotations are preserved properly, only the resolution of the type info was actually flawed. |
Suppose a class hierarchy like this:
Using Jackson on standard desktop Java SE, the following code works as expected:
However, that is not the case on Android (using the AndroidRecordModule), where the deserializer is oblivious of all class annotations (and, consequently, the JsonTypeInfo), and thus is unable to deserialize the abstract type
Field
. (abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
)I would presume that the issue lies within this code:
jackson-modules-base/android-record/src/main/java/com/fasterxml/jackson/module/androidrecord/AndroidRecordModule.java
Line 153 in 9b2fe00
Field
.My current workaround is to wrap objects akin to
Field
in this example into the following:and then change
Record
to beUsing this wrapper, deserialization works as expected on Android. However, the general issue seems to be a bug within Jackson's AndroidRecordModule.
If so desired, I'm willing to fix this myself and PR it.
The text was updated successfully, but these errors were encountered: