Skip to content

Commit 8875a9c

Browse files
committed
Try to fix #4626, #4630 (start with failing tests)
1 parent 3ed7f45 commit 8875a9c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithIgnoreOverride3992Test.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ public void testHelloRecord() throws Exception {
5050
HelloRecord result = MAPPER.readValue(json, HelloRecord.class);
5151
assertNotNull(result);
5252
}
53+
54+
// [databind#4626]
55+
@Test
56+
public void testDeserialize() throws Exception {
57+
HelloRecord expected = new HelloRecord("hello", null);
58+
59+
assertEquals(expected, MAPPER.readValue(a2q("{'text':'hello'}"), HelloRecord.class));
60+
assertEquals(expected, MAPPER.readValue(a2q("{'text':'hello','hidden':null}"), HelloRecord.class));
61+
assertEquals(expected, MAPPER.readValue(a2q("{'text':'hello','hidden':{'all': []}}"), HelloRecord.class));
62+
}
5363
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.fasterxml.jackson.databind.records;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
public class RecordWithOverriddenInclude4630Test extends DatabindTestUtil
12+
{
13+
record Id2Name(int id, String name) {
14+
}
15+
16+
record RecordWithJsonIncludeProperties(@JsonIncludeProperties("id") Id2Name child) {
17+
@Override
18+
public Id2Name child() {
19+
return child;
20+
}
21+
}
22+
23+
record RecordWithJsonIgnoreProperties(@JsonIgnoreProperties("name") Id2Name child) {
24+
@Override
25+
public Id2Name child() {
26+
return child;
27+
}
28+
}
29+
30+
private final ObjectMapper MAPPER = newJsonMapper();
31+
32+
// [databind#4630]
33+
@Test
34+
public void testSerializeJsonIncludeProperties() throws Exception {
35+
String json = MAPPER.writeValueAsString(new RecordWithJsonIncludeProperties(new Id2Name(123, "Bob")));
36+
assertEquals(a2q("{'child':{'id':123}}"), json);
37+
}
38+
39+
// [databind#4630]
40+
@Test
41+
public void testSerializeJsonIgnoreProperties() throws Exception {
42+
String json = MAPPER.writeValueAsString(new RecordWithJsonIgnoreProperties(new Id2Name(123, "Bob")));
43+
assertEquals(a2q("{'child':{'id':123}}"), json);
44+
}
45+
}

0 commit comments

Comments
 (0)