jackson-databind
jackson-databind copied to clipboard
Inconsistent handling of nil UUID in property inclusion
Describe the bug
nil UUID value is deserialized in Include.NON_DEFAULT but not in Include.NON_EMPTY
Version information 2.13.3
To Reproduce
private static ObjectMapper redisObjectMapperNonDefault() {
return new ObjectMapper().setDefaultPropertyInclusion(Include.NON_DEFAULT);
}
private static ObjectMapper redisObjectMapperNonEmpty() {
return new ObjectMapper().setDefaultPropertyInclusion(Include.NON_EMPTY);
}
public static class TestInclude {
@JsonProperty
UUID nilUUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
@JsonProperty
UUID randomUUID = UUID.randomUUID();
@JsonProperty
int defaultPrimitive;
@JsonProperty
int nonDEfaultPrimitive = 1;
}
public static void main(String[] args) throws JsonProcessingException {
final var redisObjectMapperNonDefault = redisObjectMapperNonDefault();
final var testInclude = new TestInclude();
System.out.println("NON_DEFAULT:");
System.out.println(redisObjectMapperNonDefault.writerWithDefaultPrettyPrinter().writeValueAsString(testInclude));
final var redisObjectMapperNonEmpty = redisObjectMapperNonEmpty();
System.out.println("NON_EMPTY:");
System.out.println(redisObjectMapperNonEmpty.writerWithDefaultPrettyPrinter().writeValueAsString(testInclude));
}
Result:
NON_DEFAULT:
{
"nilUUID" : "00000000-0000-0000-0000-000000000000",
"randomUUID" : "fab6a3ef-98ea-4c97-b5f0-aabee23b697b",
"nonDEfaultPrimitive" : 1
}
NON_EMPTY:
{
"randomUUID" : "fab6a3ef-98ea-4c97-b5f0-aabee23b697b",
"defaultPrimitive" : 0,
"nonDEfaultPrimitive" : 1
}
Expected behavior I would expect one of the following:
nilUUIDto be deserialized inNON_EMPTYnilUUIDnot to be serialized inNON_DEFAULT, per documentation of this modifier:All values considered "empty" (as per #NON_EMPTY) are excluded
i'm a bit confused why BeanUtil.getDefaultValue returns JsonInclude.Include.NON_EMPTY only for container and reference types, when the NON_DEFAULT spec says it should always fall back on NON_EMPTY