1212// causes deserialization to fail since 2.18.4
1313public class JsonPropertyRename5398Test extends DatabindTestUtil
1414{
15- static class Test5398 {
16- private String prop = "someValue" ;
15+ static class TestRename5398 {
16+ private String prop ;
1717
1818 @ JsonProperty (value = "renamedProp" )
1919 public String getProp () {
@@ -26,21 +26,55 @@ public void setProp(String prop) {
2626 }
2727 }
2828
29+ static class TestStd5398 {
30+ private String prop ;
31+
32+ @ JsonProperty
33+ public String getProp () {
34+ return prop ;
35+ }
36+
37+ @ JsonIgnore
38+ public void setProp (String prop ) {
39+ this .prop = prop ;
40+ }
41+ }
42+
2943 private final ObjectMapper MAPPER = newJsonMapper ();
3044
3145 @ Test
3246 public void testRenamedPropertyWithIgnoredSetter5398 () throws Exception
3347 {
34- Test5398 original = new Test5398 ();
48+ TestRename5398 original = new TestRename5398 ();
49+ original .setProp ("someValue" );
50+
3551 String json = MAPPER .writeValueAsString (original );
3652
3753 // Should serialize with renamed property
3854 assertEquals ("{\" renamedProp\" :\" someValue\" }" , json );
3955
4056 // Should be able to deserialize back (setter is ignored, so field remains default)
41- Test5398 result = MAPPER .readValue (json , Test5398 .class );
57+ TestRename5398 result = MAPPER .readValue (json , TestRename5398 .class );
58+ assertNotNull (result );
59+ // The setter is ignored but the property is still considered read-write
60+ assertEquals ("someValue" , result .getProp ());
61+ }
62+
63+ @ Test
64+ public void testStandardPropertyWithIgnoredSetter5398 () throws Exception
65+ {
66+ TestStd5398 original = new TestStd5398 ();
67+ original .setProp ("someValue" );
68+
69+ String json = MAPPER .writeValueAsString (original );
70+
71+ // Should serialize with renamed property
72+ assertEquals ("{\" prop\" :\" someValue\" }" , json );
73+
74+ // Should be able to deserialize back (setter is ignored, so field remains default)
75+ TestStd5398 result = MAPPER .readValue (json , TestStd5398 .class );
4276 assertNotNull (result );
43- // Since setter is ignored, the deserialized object should have the default value
44- assertEquals ("someValue" , result .getProp ());
77+ // The setter is ignored but the property is still considered read-write
78+ assertEquals ("someValue" , result .getProp ());
4579 }
4680}
0 commit comments