Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature improvement] Jackson should allow real inheritance without property based polymorphism #1608

Closed
jhcao23 opened this issue Apr 18, 2017 · 2 comments

Comments

@jhcao23
Copy link

jhcao23 commented Apr 18, 2017

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.

@cowtowncoder
Copy link
Member

I think this is duplicate of #43.

@cowtowncoder
Copy link
Member

Assuming this is a duplicate; if more information needed may modify #43 with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants