From ad193798bf0e9beffb33762231f9c82e70c3a4e5 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Sun, 1 Dec 2024 22:56:44 +0900 Subject: [PATCH] test : Add tofix test case for #4629 --- ...rdsWithJsonIncludeAndIgnorals4629Test.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/test-jdk17/java/com/fasterxml/jackson/databind/tofix/RecordsWithJsonIncludeAndIgnorals4629Test.java diff --git a/src/test-jdk17/java/com/fasterxml/jackson/databind/tofix/RecordsWithJsonIncludeAndIgnorals4629Test.java b/src/test-jdk17/java/com/fasterxml/jackson/databind/tofix/RecordsWithJsonIncludeAndIgnorals4629Test.java new file mode 100644 index 0000000000..ab34b55a86 --- /dev/null +++ b/src/test-jdk17/java/com/fasterxml/jackson/databind/tofix/RecordsWithJsonIncludeAndIgnorals4629Test.java @@ -0,0 +1,58 @@ +package com.fasterxml.jackson.databind.tofix; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonIncludeProperties; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; +import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +// [databind#4629] @JsonIncludeProperties & @JsonIgnoreProperties +// are ignored when deserializing Records +public class RecordsWithJsonIncludeAndIgnorals4629Test + extends DatabindTestUtil { + + record Id2Name( + int id, + String name + ) { } + + record RecordWithInclude4629( + @JsonIncludeProperties("id") Id2Name child + ) { } + + record RecordWIthIgnore4629( + @JsonIgnoreProperties("name") Id2Name child + ) { } + + private final ObjectMapper MAPPER = newJsonMapper(); + + @JacksonTestFailureExpected + @Test + void testJsonInclude4629() + throws Exception + { + RecordWithInclude4629 expected = new RecordWithInclude4629(new Id2Name(123, null)); + String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}"; + + RecordWithInclude4629 actual = MAPPER.readValue(input, RecordWithInclude4629.class); + + assertEquals(expected, actual); + } + + @JacksonTestFailureExpected + @Test + void testJsonIgnore4629() + throws Exception + { + RecordWIthIgnore4629 expected = new RecordWIthIgnore4629(new Id2Name(123, null)); + String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}"; + + RecordWIthIgnore4629 actual = MAPPER.readValue(input, RecordWIthIgnore4629.class); + + assertEquals(expected, actual); + } + +}