Use activateDefaultTyping( objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, JsonTypeInfo.As.PROPERTY); After serialization, deserialize error #224
-
After serialization, deserialize |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
|
Could you fix the markdown code-block format? with proper indents and such |
Beta Was this translation helpful? Give feedback.
-
|
This could be the usual FAQ wrt type erasure: serialization of root-level generic type ( is wrong choice IF intended base type is So may be fixed by various alternatives:
But also: if type used is |
Beta Was this translation helpful? Give feedback.
-
|
When I use ObjectMapper.DefaultTyping.NON_FINAL, there are issues with serializing and deserializing a plain List. Is there a compatible way to handle this? Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id '1' as a subtype of |
Beta Was this translation helpful? Give feedback.
-
|
In my actual scenario, when I deserialize, I don't know what type I need to deserialize into. I am actually implementing MyBatis Plus's AbstractJsonTypeHandler. |
Beta Was this translation helpful? Give feedback.
This could be the usual FAQ wrt type erasure: serialization of root-level generic type (
List).But I think this:
is wrong choice IF intended base type is
List<Person>as used forreadValue()--Personis neitherjava.lang.Objectnor "non-concrete" -- it is a concrete class (unless there's some odd Lombok magic).So may be fixed by various alternatives:
List<Object>so base type for elements isjava.lang.Objectand Type Id is expectedDefaultTypingtoDefaultTyping.NON_FINALwriteValue()target type ofList<Person>viaObjectReader: something likeObjectWriter w = mapper.writerFor(new TypeReference<Lis…