I’ve some classes A, B, C they all inherit from class BaseClass.
I’ve a String json that contains the json representation of the A, B, C or BaseClass.
I want to have some way to deserialize this String to the BaseClass (polymorphic deserialization). Something like this
BaseClass base = ObjectMapper.readValue(jsonString, BaseClass.class);
jsonString could be Json String representation of any of A, B, C, or BaseClass.
It’s not clear what problem the original poster is having. I’m guessing that it’s one of two things:
Deserialization problems with unbound JSON elements, because the JSON contains elements for which there is nothing in the Java to bind to; or
Want to implement polymorphic deserialization.
Here’s a solution to the first problem.
Here’s a solution to the second problem.
If instead, the goal is to deserialize to a subclass type without a JSON element specifically dedicated to indicate what the subclass type is, then that is also possible, so long as something in the JSON can be used to decide what the subclass type should be. I posted an example of this approach at http://programmerbruce.blogspot.com/2011/05/deserialize-json-with-jackson-into.html.