Skip to content

Commit 2df0d23

Browse files
authored
test : Add tofix test case for #4629 (#4823)
1 parent a185fbf commit 2df0d23

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.fasterxml.jackson.databind.tofix;
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 com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
12+
// [databind#4629] @JsonIncludeProperties & @JsonIgnoreProperties
13+
// are ignored when deserializing Records
14+
public class RecordsWithJsonIncludeAndIgnorals4629Test
15+
extends DatabindTestUtil {
16+
17+
record Id2Name(
18+
int id,
19+
String name
20+
) { }
21+
22+
record RecordWithInclude4629(
23+
@JsonIncludeProperties("id") Id2Name child
24+
) { }
25+
26+
record RecordWIthIgnore4629(
27+
@JsonIgnoreProperties("name") Id2Name child
28+
) { }
29+
30+
private final ObjectMapper MAPPER = newJsonMapper();
31+
32+
@JacksonTestFailureExpected
33+
@Test
34+
void testJsonInclude4629()
35+
throws Exception
36+
{
37+
RecordWithInclude4629 expected = new RecordWithInclude4629(new Id2Name(123, null));
38+
String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}";
39+
40+
RecordWithInclude4629 actual = MAPPER.readValue(input, RecordWithInclude4629.class);
41+
42+
assertEquals(expected, actual);
43+
}
44+
45+
@JacksonTestFailureExpected
46+
@Test
47+
void testJsonIgnore4629()
48+
throws Exception
49+
{
50+
RecordWIthIgnore4629 expected = new RecordWIthIgnore4629(new Id2Name(123, null));
51+
String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}";
52+
53+
RecordWIthIgnore4629 actual = MAPPER.readValue(input, RecordWIthIgnore4629.class);
54+
55+
assertEquals(expected, actual);
56+
}
57+
58+
}

0 commit comments

Comments
 (0)