-
-
Notifications
You must be signed in to change notification settings - Fork 177
Nullable String property deserializes null as "null" for JsonTypeInfo.As.EXTERNAL_PROPERTY #335
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
Any update on this? |
I added a failing test for this; haven't looked into where it's happening, though. This could be an issue in |
@cowtowncoder I can look deeper into this, but do you know if it's possible that this is part of |
@dinomite Yes, I suspect it could be something wrt |
One quick question for @jonatan-bengtsson: does this occur with 2.11.4 / 2.12.0 too? |
The test fails for 2.11.4 and 2.12.0. public class ExternalPropertyTypeShouldBeNullTest {
static class Box {
public String type;
public Fruit fruit;
public Box(@JsonProperty("type") String type,
@JsonTypeInfo(use = Id.NAME, include = As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({@Type(value = Orange.class, name = "orange")})
@JsonProperty("fruit") Fruit fruit) {
this.type = type;
this.fruit = fruit;
}
}
interface Fruit{}
static class Orange implements Fruit {
public String name;
public String color;
public Orange(@JsonProperty("name") String name, @JsonProperty("name") String color) {
this.name = name;
this.color = color;
}
}
private final ObjectMapper MAPPER = new ObjectMapper();
@Test
public void testDeserializationNull() throws Exception {
MAPPER.disable(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY);
Box deserOrangeBox = MAPPER.readValue("{\"type\":null,\"fruit\":null}}", Box.class);
assertNull(deserOrangeBox.fruit);
assertNull(deserOrangeBox.type); // error: "expected null, but was:<null>"
}
} |
Ok, I'll create a new issue for databind (could transfer but I think there is probably need to verify Kotlin side if and when databind is fixed). |
Created: |
This issue was fixed by FasterXML/jackson-databind#3008 |
Hi! 👋
I noticed that nullable String
propery
field for forJsonTypeInfo.As.EXTERNAL_PROPERTY
deserializesnull
as"null"
String, while I expected it to returnnull
.I have also tried using
ObjectMapper().registerModule(KotlinModule(nullIsSameAsDefault = true))
and setting
val type: String? = null
but without any result.
Versions
Kotlin: 1.3.72
Jackson-module-kotlin: 2.11.0
Jackson-databind: 2.11.0
The text was updated successfully, but these errors were encountered: