diff --git a/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithIgnoreOverride3992Test.java b/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithIgnoreOverride3992Test.java index faf005c4f2..a1e6478241 100644 --- a/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithIgnoreOverride3992Test.java +++ b/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithIgnoreOverride3992Test.java @@ -50,4 +50,14 @@ public void testHelloRecord() throws Exception { HelloRecord result = MAPPER.readValue(json, HelloRecord.class); assertNotNull(result); } + + // [databind#4626] + @Test + public void testDeserialize() throws Exception { + HelloRecord expected = new HelloRecord("hello", null); + + assertEquals(expected, MAPPER.readValue(a2q("{'text':'hello'}"), HelloRecord.class)); + assertEquals(expected, MAPPER.readValue(a2q("{'text':'hello','hidden':null}"), HelloRecord.class)); + assertEquals(expected, MAPPER.readValue(a2q("{'text':'hello','hidden':{'all': []}}"), HelloRecord.class)); + } } diff --git a/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithOverriddenInclude4630Test.java b/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithOverriddenInclude4630Test.java new file mode 100644 index 0000000000..a1b677f2ab --- /dev/null +++ b/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithOverriddenInclude4630Test.java @@ -0,0 +1,45 @@ +package com.fasterxml.jackson.databind.records; + +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 org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class RecordWithOverriddenInclude4630Test extends DatabindTestUtil +{ + record Id2Name(int id, String name) { + } + + record RecordWithJsonIncludeProperties(@JsonIncludeProperties("id") Id2Name child) { + @Override + public Id2Name child() { + return child; + } + } + + record RecordWithJsonIgnoreProperties(@JsonIgnoreProperties("name") Id2Name child) { + @Override + public Id2Name child() { + return child; + } + } + + private final ObjectMapper MAPPER = newJsonMapper(); + + // [databind#4630] + @Test + public void testSerializeJsonIncludeProperties() throws Exception { + String json = MAPPER.writeValueAsString(new RecordWithJsonIncludeProperties(new Id2Name(123, "Bob"))); + assertEquals(a2q("{'child':{'id':123}}"), json); + } + + // [databind#4630] + @Test + public void testSerializeJsonIgnoreProperties() throws Exception { + String json = MAPPER.writeValueAsString(new RecordWithJsonIgnoreProperties(new Id2Name(123, "Bob"))); + assertEquals(a2q("{'child':{'id':123}}"), json); + } +}