You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jackson only allow inheritance with polymorphism style such as property based definition @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property="type").
However, it is necessary to consider the situation that the subclass doesn't have this property. abstract class A {String common;} class B extends A {String nameB;} class C extends A {String type, extra;}
if the give json string is String content = "{ name_b: bbb }";, we want Jackson to be able to automatically cast it to B even the given result type is A: A a = objectMapper.readValue(content, A.class);
i.e.: a instanceof B should return true and yes, A should be a B.
I believe this robust feature which requires tree-like traversal and reflection checking is what we need in a lot of real scenarios, especially when the expecting response json is an array of A which could be any subclass of A like B and C etc.
The text was updated successfully, but these errors were encountered:
Jackson only allow inheritance with polymorphism style such as property based definition
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property="type")
.However, it is necessary to consider the situation that the subclass doesn't have this property.
abstract class A {String common;}
class B extends A {String nameB;}
class C extends A {String type, extra;}
if the give json string is
String content = "{ name_b: bbb }";
, we want Jackson to be able to automatically cast it to B even the given result type is A:A a = objectMapper.readValue(content, A.class);
i.e.:
a instanceof B
should return true and yes, A should be a B.I believe this robust feature which requires tree-like traversal and reflection checking is what we need in a lot of real scenarios, especially when the expecting response json is an array of A which could be any subclass of A like B and C etc.
The text was updated successfully, but these errors were encountered: