How to map OneToOne relationships between POJOs using @JsonManagedReference and @JsonBackReference

I read

looking for solutions to match one-to-one relationships. However, these article demonstrations are Many-to-One or One-to-Many. From the demo, I came to the conclusion that in most cases we will comment on one side as @JsonManagedReference and MANY as @JsonBackReference.

However, there are no hints about how to match one-to-one. Do you have any ideas?

Also, what if it's bidirectional one-to-one?

+7
source share
1 answer

You can see this as a one-to-many special case; therefore, you will annotate the link from parent to "child" as @JsonManagedReference, and "child" - "parent" as @JsonBackReference.

Another document that may be helpful is the FasterXML Jackson Wiki ; the first example is for a one-to-one relationship and should be applicable to your case.

+15
source

All Articles