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?
Comment From: cowtowncoder
I doubt this is possible to support, unfortunately, due to immutable nature of records, and fundamental cyclic aspect of parent/child relationship.
Which means it'd probably be good to pro-actively fail on attempts to use these annotations with Records.