Nan
Nan

Reputation: 339

jackson bi-directional mapping

I have a oneToMany bi-direction relationship between a parent and it's children, 2 jsp page to display the data. for the parent page, it shows the parents and underlying children. and in the child page, it shows the child and its parent. so I need a bi-direction structure.

Parent page: Parent to child child page: Child to parent

I use jackson and try to use @JsonBackReference, but this actually skip a one way relationship. what's the right way to do this? I know if I only set one way relation it can work. but because I use jpa and need to load the data in both way. it means I have to trim down one way after I load it.

Upvotes: 0

Views: 661

Answers (1)

Brian Clozel
Brian Clozel

Reputation: 59211

It looks like you want to (de)serialize a cyclic graph without going in an "infinite loop".

The @JsonIdentityInfo annotation is quite nice for that, but I guess it wouldn't work within a JSP: you're probably loading JSON data with AJAX and I think JSON.parse() doesn't support object references.

Or you could use a custom serializer. As far as I know, there's no simple way to give Jackson information on the serialization context; one could achieve that using Jackson Value Injection or storing data in a ThreadLocal.

Upvotes: 0

Related Questions