jackson-databind
jackson-databind copied to clipboard
Support JsonManagedReference/JsonBackReference for records
Is your feature request related to a problem? Please describe.
Currently, it isn't possible to use records with JsonManagedReference/JsonBackReference as records do not have a mutator available. Would it be possible to support this?
Describe the solution you'd like
Ability to use the existing annotations
Usage example
public class RecordTest {
public static void main(String[] args) throws Exception {
final var objectMapper = new ObjectMapper();
final var json = "{\"children\":[{}]}";
final var parent = objectMapper.readValue(json, Parent.class);
assertThat(parent.children())
.hasSize(1)
.element(0)
.extracting(Child::parent)
.isNotNull();
}
record Parent(@JsonManagedReference List<Child> children) {}
record Child(@JsonBackReference Parent parent) {}
}
Additional context
Is there a workaround whilst still being able to use records?