Jackson has a great feature that allows performing polymorphic deserialization without changing the JSON structure. Here's the example. However, I can't use it since it requires adding annotations like @JsonTypeInfo(use=Id.DEDUCTION)
and @JsonSubTypes({ ... })
to classes that, in my case, are generated.
I am looking for ways to achieve the same behavior without changing the source code of POJOs. For example, are there any ways to do it by configuring the object mapper itself?
ObjectMapper MixIns seem to be exactly what you're looking for.
Create a class stub like:
Then register it with your ObjectMapper like: