File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
src/test/java/tools/jackson/databind/tofix Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ package tools .jackson .databind .tofix ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import com .fasterxml .jackson .annotation .JsonCreator ;
6+ import com .fasterxml .jackson .annotation .JsonIgnore ;
7+ import com .fasterxml .jackson .annotation .JsonProperty ;
8+
9+ import tools .jackson .databind .ObjectMapper ;
10+ import tools .jackson .databind .testutil .failure .JacksonTestFailureExpected ;
11+
12+ import static org .junit .jupiter .api .Assertions .*;
13+ import static tools .jackson .databind .testutil .DatabindTestUtil .*;
14+
15+ // From https://github.com/FasterXML/jackson-module-kotlin/issues/308
16+ /**
17+ * Test for verifying that {@link JsonIgnore} on a field combined with
18+ * {@link JsonProperty} on a private setter method works correctly.
19+ * The private method "unpacks" the JSON property value to a different field.
20+ */
21+ public class KotlinIssue308JsonIgnoreTest
22+ {
23+ static class TestDto
24+ {
25+ @ JsonIgnore
26+ Integer id ;
27+
28+ Integer cityId ;
29+
30+ @ JsonCreator
31+ public TestDto (Integer id , Integer cityId ) {
32+ this .id = id ;
33+ this .cityId = cityId ;
34+ }
35+
36+ @ JsonProperty ("id" )
37+ void unpackId (Integer idObj ) {
38+ cityId = idObj ;
39+ }
40+ }
41+
42+ private final ObjectMapper MAPPER = newJsonMapper ();
43+
44+ @ JacksonTestFailureExpected
45+ @ Test
46+ public void testJsonIgnoreWithJsonPropertyUnpacker () throws Exception
47+ {
48+ TestDto dto = MAPPER .readValue ("{\" id\" :12345}" , TestDto .class );
49+
50+ assertNotNull (dto );
51+ assertEquals (Integer .valueOf (12345 ), dto .cityId );
52+ assertNull (dto .id );
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments