Skip to content

Prevent use of unsupported @JsonManagedReference/@JsonBackReference for Record-valued properties #5188

Description

@JBodkin-Amphora

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.1RecordIssue related to JDK17 java.lang.Record support

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions