Nulls
property metadata not working for records (original) (raw)
Describe the bug
Nulls.AS_EMPTY does not work for JDK14 records, it deserializes null as null and should be an empty list
Version information
2.12.0
To Reproduce
record SomeRecord(
@JsonSetter(contentNulls = Nulls.AS_EMPTY, nulls = Nulls.AS_EMPTY)
List<String> someCollection
) {
}
@Test
void collection_is_null() throws JsonProcessingException {
var mapper = new ObjectMapper();
mapper.setDefaultSetterInfo(JsonSetter.Value.construct(Nulls.AS_EMPTY, Nulls.AS_EMPTY));
assertThat(mapper.readValue("{}", SomeRecord.class).someCollection(), is(nullValue()));
}
Expected behavior
mapper.readValue("{}", SomeRecord.class).someCollection() should be an empty list
Additional context
I think it's a bug, I've tried to dig a bit in the code but I have no clue. If you can point me in some direction maybe I can try to arrange a PR