-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
In 2.15 trying to encode records with PropertyAccessor.GETTER = Visibility.NONE will result in an empty object {}.
record DataObject (int a, int b) {}
@Test
public void testRecord() throws Exception {
final ObjectMapper jsonMapper = new JsonMapper();
final String r = jsonMapper.writeValueAsString(new DataObject(2, 3));
jsonMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
jsonMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
Assertions.assertEquals("{\"a\":2,\"b\":3}", r); // we get {}
}
to resolve that we can set PropertyAccessor.GETTER = Visibility.DEFAULT or others, but that will break every single class serialization that does not have annotations on getter methods.
public class Foo {
private final int x = 2;
public int getComputedValue() { return 11; }
}
jsonMapper.writeValueAsString(new Foo()) // { x: 2, computedValue: 11 }
The behaviour in 2.14 with PropertyAccessor.GETTER = Visibility.NONE is the expected one, with records able to serialize all fields
Is this change something done on purpose? are there alternatives to set the visibility of getters and annotate every class method?
matt-snider
Metadata
Metadata
Assignees
Labels
No labels