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.
Comment From: JooHyukKim
Proactively you mean during introspection, detect such usage, then throw error?
Comment From: cowtowncoder
Yes
On Sun, Jun 15, 2025 at 9:01 AM Kim, Joo Hyuk @.***> wrote:
JooHyukKim left a comment (FasterXML/jackson-databind#5188) https://github.com/FasterXML/jackson-databind/issues/5188#issuecomment-2974146507
Proactively you mean during introspection, detect such usage, then throw error?
— Reply to this email directly, view it on GitHub https://github.com/FasterXML/jackson-databind/issues/5188#issuecomment-2974146507, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAANOGM2EZQQXHAFH63L6B33DWKGZAVCNFSM6AAAAAB7EYDIG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZUGE2DMNJQG4 . You are receiving this because you commented.Message ID: @.***>