Skip to content

Use activateDefaultTyping( objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, JsonTypeInfo.As.PROPERTY); After serialization, deserialize error #224

Closed Answered by cowtowncoder
superwen0001 asked this question in Q&A
Discussion options

You must be logged in to vote

This could be the usual FAQ wrt type erasure: serialization of root-level generic type (List).
But I think this:

ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE,

is wrong choice IF intended base type is List<Person> as used for readValue() -- Person is neither java.lang.Object nor "non-concrete" -- it is a concrete class (unless there's some odd Lombok magic).

So may be fixed by various alternatives:

  1. Use readValue target of List<Object> so base type for elements is java.lang.Object and Type Id is expected
  2. Change DefaultTyping to DefaultTyping.NON_FINAL
  3. Use writeValue() target type of List<Person> via ObjectReader: something like ObjectWriter w = mapper.writerFor(new TypeReference<Lis…

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@cowtowncoder
Comment options

Comment options

You must be logged in to vote
2 replies
@superwen0001
Comment options

@cowtowncoder
Comment options

Answer selected by JooHyukKim
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JooHyukKim
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants