-
Notifications
You must be signed in to change notification settings - Fork 245
JsonTypeInfo with defaultImpl is generated as required property #480
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
Comments
I tried it, here is my example: @JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type",
defaultImpl = MyClass1.class)
@JsonSubTypes({
@JsonSubTypes.Type(value = MyClass1.class, name = "class1"),
@JsonSubTypes.Type(value = MyClass2.class, name = "class2"),
})
interface MyInterface {
public String getText();
}
class MyClass1 implements MyInterface {
public String getText() {
return "text1";
}
}
class MyClass2 implements MyInterface {
public String getText() {
return "text2";
}
} When I deserialize JSON the discriminant property is really optional: But when instance of So in one direction I agree that it would be slightly better to generate this property as optional because it is easier in TypeScript to handle property marked as optional when it isn't than to handle required property when it isn't. But since none of these cases are 100% correct I would leave it as it is now because of backwards compatibility. |
I suppose properties those type depends on direction could work with microsoft/TypeScript#43662 |
Jackson allows to specify a
JsonTypeInfo.defaultImpl
on an interface. If such annotation is present, the client doesn't need to specify@class
/@type
in the JSON object when pushing data.Therefore, it would also be expected that the TS generates such property as optional, in the case a
defaultImpl
was specified.The text was updated successfully, but these errors were encountered: