If I have a class structure like so:
public abstract class Parent {
private Long id;
...
}
public class SubClassA extends Parent {
private String stringA;
private Integer intA;
...
}
public class SubClassB extends Parent {
private String stringB;
private Integer intB;
...
}
Is there an alternative way to deserialize different then @JsonTypeInfo
? Using this annotation on my parent class:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "objectType")
I would rather not have to force clients of my API to include "objectType": "SubClassA"
to deserialize a Parent
subclass.
Instead of using @JsonTypeInfo
, does Jackson provide a way to annotate a subclass and distinguish it from other subclasses via a unique property? In my example above, this would be something like, "If a JSON object has "stringA": ...
deserialize it as SubClassA
, if it has "stringB": ...
deserialize it as SubClassB
".
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…