-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Polymorphic deserialization doesn't deserialize base class fields #262
Comments
What versions of jackson and the scala module are you using? |
@nbauernfeind I'm using jackson/scala module version 2.7.3 on scala-2.10.4 |
@nbauernfeind any ideas? Can I help somehow? I'd love to get this resolved or at least have a workaround |
@devshorts Make sure to try out newer versions; 2.7.4 had important fixes in type resolution. And |
Ok cool, I'll give it a shot tomorrow |
@cowtowncoder i tried 2.7.4 and used the 2.7.5 databind but still no dice. the base class fields are still not serialized into the type. Do you have any other suggestions, as this is becoming a big issue for my codebase |
@devshorts Unfortunately I am not familiar with this module (or, Scala) so all I know is how Java side works. There are 2 main possiiblities here; either it is something general that About the only suggestions I have is to make 100% sure versions are like you say if you haven't done that. With maven it'd be You may also want to ask this on |
Ok thanks. Interestingly enough it works fine if the base trait is an abstract class and not a trait |
That does seem weird. Not sure if it's basic class-vs-interface difference, or something with Scala type introspection. |
For completeness (in case someone finds this issue later), I did verify that I was using 2.7.5 databind and scala jackson 2.7.4 via the dependency tree. And here is the jackson-users discussion: https://groups.google.com/forum/#!topic/jackson-user/f1G3E6U9W84 |
Actually I do have one more hypothesis: perhaps use of traits will add "invisible" intermediate classes between base class and implementation class, and this/these additional layer(s) could be the difference between abstract class approach. If so, perhaps it would be possible to reproduce the issue. If so, the problem would very likely be within Would it be easy enough to have a look at actual generated classes, to see how traits in this case translate to classes that JVM sees? |
@cowtowncoder sure can. Here is the decompiled (via jdgui) representation: This is with traits
This is with an abstract class
I wonder if the issue is that when its a trait the subclasses are not bound to the tame type heirarchy with the base class. The base class is "mixed in" with each of the subclasses, so the interface itself doesn't know about those properties. But when its with an abstract class the serializer can tell that a |
If I make the
|
I have a heirarchy like:
Where the base class that all sub classes inherit from looks like:
When I deserialize json like below, which contains the fields of a subclass and the base class together:
I get an instance of the class
DefaultMessage
properly since it is the default implementation, and I get thesub
field of foo which is the field of the subclass, but I don't get thebase
of bar which is the field of the base classIf I deserialize directly to the
DefaultMessage
class instead of from the trait I get the field. So it seems that somehow the polymorphic serialization is not doing the base class?Here is a full test:
The text was updated successfully, but these errors were encountered: