-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Workaround for combining @JsonUnwrapped and @JsonTypeInfo? #4698
Comments
Quick note: I'd recommend trying this out with |
Thanks for the tip! Gave it a try, but observing same issue. FWIW, the records are a mere example. The issue is the same with any POJO. |
Ok just wanted to rule out any possibility of property-introspection fixes (which include improvements to Creator handling, which while essential to Records also affects Constructor usage by POJOs) in 2.18 might have helped. But looking at this more closely... this won't work now, or possibly, ever. Further problems are conflict between generic and polymorphic types (won't play nicely). So I suspect that to make things work, you will need to change the set up -- as things are declared this is unlikely to be workable with Jackson (at least without custom (de)serializers, but writing those is lots of work). |
Search before asking
Describe the bug
It is currently not possible to combine
@JsonUnwrapped
with generic types using@JsonTypeInfo
Version Information
2.17.2
Reproduction
I have a generic
Versioned<T>
type containing aint version()
and a payloadT item()
. I'd like to be able to (de)serialize this using@JsonUnwrapped
, but cannot seem to get this to work together with the necessary@JsonTypeInfo
to deal with the generic types.Take the following types
And the following example
I would expect this produce the following JSON:
But this does not work. Even when disabling
SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS
it still does drops the@class
property, making deserialization fail.Expected behavior
No response
Additional context
I found a bunch of threads from 10+ years ago where this was not supported through Jackson. I hope this has changed by now. It is not clear to me from this simple example why this is not supported.
Alternatively, I tried to create a manual
StdSerializer
andStdDeserializer
but was unable to get the@JsonTypeInfo
annotation to work. Any examples given would be great!The text was updated successfully, but these errors were encountered: