-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Deserialize with multiple levels of polymorphic type hierachy #374
Comments
This is not supported and there are no plans to extend type resolution in this direction. Technically it will be challenging to try to do this using standard resolution mechanism due to need to correlated values of multiple properties, so your best bet is probably fully custom serializers and deserializers. |
So then, what is supported through those annotations is just one level polymorphism?
The only way to support that would be through custom serialization? Like here: https://gist.github.com/s-j/8864592 ? EDIT:
|
No, full inheritance is supported, but you can not use separate type discriminator properties: it is not possible to use, say "type" AND "subtype" -- you must use just one like "type". Subtype dependencies may be defined in chaining fashion as you mentioned (from parent to intermediate subtype; from intermediate subtype to further subtypes). |
I have a similar problem, i have 3 class, abstract class generic (), class class1 extends generic() and class11 extends class1() : @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value=CardActivityTable.class, name="5") })
@Document(collection = Card.COLLECTION_NAME)
public abstract class Card extends AuditableEntity {
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "typeActivity")
@JsonSubTypes({ @JsonSubTypes.Type(value = CardActivity.class, name = 3) })
@Document(collection = Card.COLLECTION_NAME)
public class CardActivityTable extends Card {
}
@Document(collection = Card.COLLECTION_NAME)
public class CardActivity extends CardActivityTable {
public String optionC;
} I'm trying to insert the json: {
"type":"5",
"typeActivity": "3",
"optionC": "test"
} but i show the error : "Could not read document: Unrecognized field "optionC" |
@jamarillo possibly -- and as you noticed, support for multi-level resolution does not exist nor is planned. So chaining of definitions will not work. |
@cowtowncoder
I tried custom JsonDeserialize but didn't work. Waiting for response. |
@hrishikesh-kumar It is not supported and there are no plans to support it. Do not design your system assuming this will be implemented. And I have no idea what " tried custom JsonDeserialize but didn't work." means -- custom deserializers can support LITERALLY anything. |
It seems that this use case is not supported:
What I want is to resolve this one: { "type": "b1"; ... } to class B1, and { "type": "b2"; "subtype": "c1"; ... } to class C1 and { "type": "b2"; "subtype": "c2"; ... } to class C2. (B1 has no "subtype" property, while C1 and C2 have the same "type" property and different "subtype" property)
Any suggestions?
The text was updated successfully, but these errors were encountered: