Skip to content

Commit 2011c86

Browse files
authored
Add failing test for [kotlin-module#308] (#5459)
1 parent 9f9436a commit 2011c86

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

0 commit comments

Comments
 (0)