简体   繁体   中英

Jackson annotations with hibernate orm

I have 2 classes. Parent & Child models(spring with hibernate).

A parent can have any number of children, each child has only one parent.

class Parent{
 @OneToMany(mappedBy="parent")
 private List<Child> children;
}

class Child{
 @ManyToOne
 Private Parent parent;
}

Required Json output:

  1. When i request a parent , i should get all its children along with that, but each child should not contain its parent info again.

  2. When i request for a child , i should get its parent along with that, but its parent should not contain all its children info.

What type of jackson annotations should i use for this

refer @JsonView to generate different views of the same entity.

  • when it is specified over a variable or getter it binds that variable to a view.

  • when it is specified over a controller it defines which view to return for returned entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM