Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// causes deserialization to fail since 2.18.4
public class JsonPropertyRename5398Test extends DatabindTestUtil
{
static class Test5398 {
private String prop = "someValue";
static class TestRename5398 {
private String prop;

@JsonProperty(value = "renamedProp")
public String getProp() {
Expand All @@ -26,21 +26,55 @@ public void setProp(String prop) {
}
}

static class TestStd5398 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwtw, I suspect we have test for this case somewhere. But I guess it shouldn't hurt to have some redundancy.

private String prop;

@JsonProperty
public String getProp() {
return prop;
}

@JsonIgnore
public void setProp(String prop) {
this.prop = prop;
}
}

private final ObjectMapper MAPPER = newJsonMapper();

@Test
public void testRenamedPropertyWithIgnoredSetter5398() throws Exception
{
Test5398 original = new Test5398();
TestRename5398 original = new TestRename5398();
original.setProp("someValue");

String json = MAPPER.writeValueAsString(original);

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

// Should be able to deserialize back (setter is ignored, so field remains default)
Test5398 result = MAPPER.readValue(json, Test5398.class);
TestRename5398 result = MAPPER.readValue(json, TestRename5398.class);
assertNotNull(result);
// The setter is ignored but the property is still considered read-write
assertEquals("someValue", result.getProp());
}

@Test
public void testStandardPropertyWithIgnoredSetter5398() throws Exception
{
TestStd5398 original = new TestStd5398();
original.setProp("someValue");

String json = MAPPER.writeValueAsString(original);

// Should serialize with renamed property
assertEquals("{\"prop\":\"someValue\"}", json);

// Should be able to deserialize back (setter is ignored, so field remains default)
TestStd5398 result = MAPPER.readValue(json, TestStd5398.class);
assertNotNull(result);
// Since setter is ignored, the deserialized object should have the default value
assertEquals("someValue", result.getProp());
// The setter is ignored but the property is still considered read-write
assertEquals("someValue", result.getProp());
}
}