-
-
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
EXTERNAL_PROPERTY
doesn't work with @JsonIgnoreProperties
#2610
Comments
I think this is Kotlin-specific, as data classes handling of creators, null checks, is quite customized. May be transferred back if Java-only reproduction exists (if so let me know and I can move it). |
Yes, it is not reproducible with Java. At least with my test code: @JsonIgnoreProperties(ignoreUnknown = true)
class Value {
String type;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
property = "type",
defaultImpl = Default.class
)
Default data;
}
class Default {}
String data = "[{\"type\": \"test\",\"data\": {},\"additional\": {}}]";
ObjectMapper mapper = new ObjectMapper();
List<Value> result = mapper.readValue(data, new TypeReference<List<Value>>() {}); |
Thank you for verifying: this should help in pinpointing the problem. |
I think the problem is here. This I'll try to submit a pull request that fixes it. |
I was wrong. It the |
With this new knowledge I was able to reproduce the issue with Java: @JsonIgnoreProperties(ignoreUnknown = true)
class Value {
private String type;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
property = "type",
defaultImpl = Default.class
)
private Default data;
@JsonCreator
public Value(
@JsonProperty(value = "type", required = true) String type,
@JsonProperty(value = "data", required = true) Default data
) {
this.type = type;
this.data = data;
}
}
class Default {}
String data = "[{\"type\": \"test\",\"data\": {},\"additional\": {}}]";
ObjectMapper mapper = new ObjectMapper();
List<Value> result = mapper.readValue(data, new TypeReference<List<Value>>() {}); The key difference here is to use the constructor for deserialization and require all properties. If properties are not required then the deserializer will put the second empty So it's a Java issue. @cowtowncoder could you transfer it back? |
@ashlanderr Yes, thank you for reproduction, will transfer. |
I am using polymorphic deserialization with Kotlin data classes like this:
trying to deserialize:
and I get this error:
If I will remove "additional" property from serialized JSON, add "additional" property to the Value class, or remove polymorphic deserialization, then the error will go away. I am using
@JsonIgnoreProperties(ignoreUnknown = true)
annotation, so I expected that the original case would work.Jackson Version: 2.10.2
The text was updated successfully, but these errors were encountered: