Skip to content

When Include.NON_DEFAULT setting is used on POJO, empty values are not included in json if default is null #4741

Closed
@ragnhov

Description

@ragnhov

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

After upgrading to 2.18.0, empty Strings/objects are no longer included in json output if NON_DEFAULT annotation is used on the class and the default value is null. This is possibly related to fixing #4464
As far as I can understand, the documentation states that the test below should pass, as it does in 2.17.1.
image

Version Information

2.18.0

Reproduction

@Test
void testSerialization() throws JsonProcessingException {
    MyString input = new MyString();
    input.setValue("");
    ObjectMapper objectMapper = new ObjectMapper();
    String json = objectMapper.writeValueAsString(input);
    MyString output = objectMapper.readValue(json, MyString.class);
    assertEquals(input.getValue(), output.getValue());
}

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@Data
public static class MyString {
    private String value = null;
}

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions