jackson-databind
jackson-databind copied to clipboard
When Include.NON_DEFAULT setting is used on POJO record, empty values are not included in json if default is null
Search before asking
- [X] I searched in the issues and found nothing similar.
Describe the bug
Same issue as in https://github.com/FasterXML/jackson-databind/issues/4741, but happens when the target is a record instead of a class. Empty Strings/objects are not included in json output if NON_DEFAULT annotation is used on a record and the default value is null.
Version Information
2.18.1, 2.18.2
Reproduction
class JacksonTest {
@JsonInclude(Include.NON_DEFAULT)
record Record(String property) {}
@JsonInclude(Include.NON_DEFAULT)
@AllArgsConstructor
@NoArgsConstructor
@Getter
static class NonRecord {
private String property;
}
@Test
void test() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
assertThat(mapper.writeValueAsString(new Record("")))
.isEqualTo(mapper.writeValueAsString(new NonRecord("")));
}
}
expected: "{"property":""}"
but was: "{}"
Expected behavior
No response
Additional context
No response