0

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

lch
  • 4,569
  • 13
  • 42
  • 75

1 Answers1

0

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.

mayank393
  • 1
  • 1