Jackson Inheritance and Deserialization

I am writing an API on top of Spring Web MVC / Spring Hateoas, and even if deserializing a simple class hierarchy works like a charm, I will not be able to deserialize the Json input for the correct type using jackson. Here is my class hierarchy:

public class A {
    protected String fieldA;
}

public class B extends A {
    protected String fieldB;
}

public class C extends A {
    protected String fieldC;
}

Before everyone sends me to many other similar questions on SO, the main difference here is that A is specific . In other words, Jackson has to choose between 3 implementations, using json fields as delimiters.

Basically, how to configure Jackson for deserialization:

{
    "fieldA": "asdf"
} 

to instance A and

{
    "fieldA": "asdf",
    "fieldB": "asdf"
} 

to instance B?

+3
source share
1 answer

: - ( , ). , ( ) .

, , , JsonDeserializer . , ConvertingDeserializer, JSON JsonNode java.util.Map, .

+3

All Articles