Closed
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
While working on #4388 , found some unexpected behavior.
Behavior as title.
Will file a reproductino PR
Version Information
Tested and does not work on...
- 2.18.2
- 2.19
Reproduction
public class ShapeArrayWithAnyGetterTest
extends DatabindTestUtil
{
static class WrapperForAnyGetter {
public BeanWithAnyGetter value;
}
@JsonPropertyOrder({ "firstProperty", "secondProperties", "anyProperty", "forthProperty" })
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
static class BeanWithAnyGetter {
public String firstProperty = "first";
public String secondProperties = "second";
public String forthProperty = "forth";
@JsonAnyGetter
public Map<String, String> getAnyProperty() {
Map<String, String> map = new TreeMap<>();
map.put("third_A", "third_A");
map.put("third_B", "third_B");
return map;
}
}
final ObjectMapper MAPPER = newJsonMapper();
@Test
public void testSerializeArrayWithAnyGetterWithWrapper() throws Exception {
WrapperForAnyGetter wrapper = new WrapperForAnyGetter();
wrapper.value = new BeanWithAnyGetter();
String json = MAPPER.writeValueAsString(wrapper);
// Fails Actual :{"value":{"firstProperty":"first","secondProperties":"second","forthProperty":"forth","third_A":"third_A","third_B":"third_B"}}
assertEquals(a2q("{'value':" +
"[" +
"'first'," +
"'second'," +
"'forth'," +
"'third_A'," +
"'third_B'" +
"]" +
"}"), json);
}
@Test
public void testSerializeArrayWithAnyGetterAsRoot() throws Exception {
BeanWithAnyGetter bean = new BeanWithAnyGetter();
String json = MAPPER.writeValueAsString(bean);
// Fails Actual : {"firstProperty":"first","secondProperties":"second","forthProperty":"forth","third_A":"third_A","third_B":"third_B"}
assertEquals(a2q("[" +
"'first'," +
"'second'," +
"'forth'," +
"'third_A'," +
"'third_B'" +
"]"), json);
}
}
Expected behavior
No response
Additional context
No response