Skip to content

Commit f6c2512

Browse files
committed
Merge branch '3.0' into 3.x
2 parents 77fdc9e + 129774d commit f6c2512

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/test/java/tools/jackson/databind/introspect/JsonPropertyRename5398Test.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// causes deserialization to fail since 2.18.4
1414
public class JsonPropertyRename5398Test extends DatabindTestUtil
1515
{
16-
static class Test5398 {
17-
private String prop = "someValue";
16+
static class TestRename5398 {
17+
private String prop;
1818

1919
@JsonProperty(value = "renamedProp")
2020
public String getProp() {
@@ -27,21 +27,55 @@ public void setProp(String prop) {
2727
}
2828
}
2929

30+
static class TestStd5398 {
31+
private String prop;
32+
33+
@JsonProperty
34+
public String getProp() {
35+
return prop;
36+
}
37+
38+
@JsonIgnore
39+
public void setProp(String prop) {
40+
this.prop = prop;
41+
}
42+
}
43+
3044
private final ObjectMapper MAPPER = newJsonMapper();
3145

3246
@Test
3347
public void testRenamedPropertyWithIgnoredSetter5398()
3448
{
35-
Test5398 original = new Test5398();
49+
TestRename5398 original = new TestRename5398();
50+
original.setProp("someValue");
51+
3652
String json = MAPPER.writeValueAsString(original);
3753

3854
// Should serialize with renamed property
3955
assertEquals("{\"renamedProp\":\"someValue\"}", json);
4056

4157
// Should be able to deserialize back (setter is ignored, so field remains default)
42-
Test5398 result = MAPPER.readValue(json, Test5398.class);
58+
TestRename5398 result = MAPPER.readValue(json, TestRename5398.class);
59+
assertNotNull(result);
60+
// The setter is ignored but the property is still considered read-write
61+
assertEquals("someValue", result.getProp());
62+
}
63+
64+
@Test
65+
public void testStandardPropertyWithIgnoredSetter5398() throws Exception
66+
{
67+
TestStd5398 original = new TestStd5398();
68+
original.setProp("someValue");
69+
70+
String json = MAPPER.writeValueAsString(original);
71+
72+
// Should serialize with renamed property
73+
assertEquals("{\"prop\":\"someValue\"}", json);
74+
75+
// Should be able to deserialize back (setter is ignored, so field remains default)
76+
TestStd5398 result = MAPPER.readValue(json, TestStd5398.class);
4377
assertNotNull(result);
44-
// Since setter is ignored, the deserialized object should have the default value
45-
assertEquals("someValue", result.getProp());
78+
// The setter is ignored but the property is still considered read-write
79+
assertEquals("someValue", result.getProp());
4680
}
4781
}

0 commit comments

Comments
 (0)