jackson defaultImpl incase of subtype extending another subtype of parent class not working

8 views
Skip to first unread message

Avinash Vundyala

unread,
Jul 1, 2019, 10:44:26 AM7/1/19
to jackson-user

My class Subtype structure looks like:

       A
      / \
     B   C
    /     \
   D       E

and using Jackson to deserialize JSON and when I mention defaultImpl to class A then I get:

Class A not subtype of [simple type, class B]

can you please point out how to get the defaultImpl to work in case of missing type id property

Tatu Saloranta

unread,
Jul 1, 2019, 4:48:38 PM7/1/19
to jackson-user
I'd need to know exact calls you are using (and probably
`@JsonTypeInfo` definitions); class hierarchy itself is not
sufficient.
And perhaps specific failure you get.

But one common problem is that users sometimes try to use a subtype as
target type on deserialization (like `B` or `C`) -- but `defaultImpl`
MUST be assignment compatible with given target type.
So it could be that you were trying something like:

B result = mapper.readValue(source, B.class);

in which case you saying that base type of result value is `B`, and
therefore `A` would not be assignment-compatible default type.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages