Problem with `JsonTypeInfo.As.EXISTING_PROPERTY`, `@JsonValue`/`@JsonCreator` combination
See original GitHub issueLooks like there is a regression in handling of polymorphic type that uses @JsonAnyGetter
as well as
EXISTING_PROPERTY` type id inclusion.
Failing test was provided by @carterkozak via #2952.
NOTE: instead of @JsonAnyGetter
it looks like the issue is rather with @JsonValue
, TypeSerializer
/TypeDeserializer
access.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Jackson @JsonValue is conflicting with @JsonTypeInfo
Try to set @JsonTypeInfo.include to JsonTypeInfo.As.EXISTING_PROPERTY @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.
Read more >Inheritance in Jackson | Baeldung
This tutorial will demonstrate how to handle inclusion of subtype metadata and ignoring properties inherited from superclasses with Jackson.
Read more >Jackson Json - @JsonTypeInfo, using Logical Type Name ...
Id.CLASS which causes fully-qualified Java class name to be serialized as the type identifier. Java class name may not be a good choice...
Read more >Security update for jackson-databind, jackson-dataformats ...
As.EXISTING_PROPERTY + Can not deserialize json to enum value with Object-/Array-valued input, '@JsonCreator' + Fix to avoid problem with ...
Read more >JsonSerialize, JsonTypeInfo not working, JsonAnyGetter ...
The @JsonCreator annotation can be used on constructors or factory methods for mapping incoming JSON properties to the constructor/factory method arguments.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@carterkozak glad to know you were able to figure out a setting that works in both cases, as I realize that this is quite complicated use case. I hope we are getting closer to getting things to work consistently so such changes to observed behavior are not needed. Thank you very much for reporting these issues!
One remaining possible challenge is the problem of duplicated properties for type ids – that is,
TypeSerializer
writing its entry but there also being a regular property with same name. I hope that could be resolved in 2.13.As per above discussion I think the new behavior is expected one and what is defined as “works as expected” form 2.12 onwards. Closing.