Skip to content

JsonSetter.contentNulls propagates unexpectedly into nested structures #5742

@k163377

Description

@k163377

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

JsonSetter.contentNulls should fundamentally only apply to the explicitly provided parameters.
That is, if this specification is applied to a parameter like List<List<String>>, [null] should be rejected, but [[null]] should be allowed.

However, in practice, [[null]] is rejected.

Version Information

3.1.0

Reproduction

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class Kotlin1064Test {
    record Dst(
            @JsonSetter(contentNulls = Nulls.FAIL)
            List<List<String>> foo
    ) {}

    @Test
    public void test() {
        var mapper = JsonMapper.builder().build();

        assertThrows(InvalidNullException.class, () -> mapper.readValue("{\"foo\":[null]}", Dst.class));
        // fails
        assertDoesNotThrow(() -> mapper.readValue("{\"foo\":[[null]]}", Dst.class));
    }
}

Expected behavior

No response

Additional context

This relates to the following issues.
FasterXML/jackson-module-kotlin#1064

While it's hard to say what behavior is ideal, having Nulls.FAIL applied to the entire nested structure feels a bit cumbersome to handle.

Also, I don't have a specific design in mind yet, but I feel that fundamentally, we might need to change the structure of JsonSetter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-evaluateIssue that has been received but not yet evaluated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions