For polymorphic deserialisation, Jackson's ObjectMapper wants to know:
- Which Subtypes are there to consider
- How to decide, which Subtype to use
There are some standard ways, using fully qualified class names and certain reserved JSON properties, so Jackson can deduct those things without further configuration.
Another common way is, to provice Jackson with the necessary infromation by adding the Annotations @JsonTypeInfo and @JsonSubtypes to the base type. This however implies, that the file, declaring the base class has to be modified, when ever a new subtype is added.
It is also possible to regiser subtypes to the ObjectMapper programmatically at runtime via objectMapper.registerSubtypes(...).
Now I am looking for a way to also provide the information from @JsonTypeInfo programmatically at runtime without using that annotation.
Somthing like objectMapper.addTypeInfo(new TypeInfo(BaseType.class, PROPERTY, "myPropertyName", NAME); so I can use polymorphic deserialization on types that are declared in another project, that knows nothing of Jackson or any of its annotations.