[英]Jackson annotations with hibernate orm
I have 2 classes. 我有2节课。 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: 所需的Json输出:
When i request a parent , i should get all its children along with that, but each child should not contain its parent info again. 当我请求父母时 ,我应该将其所有子女都带走,但每个子女都不应再次包含其父母信息。
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. 请参考@JsonView以生成同一实体的不同视图。
when it is specified over a variable or getter it binds that variable to a view. 当在变量或getter上指定它时,它将该变量绑定到视图。
when it is specified over a controller it defines which view to return for returned entity. 在控制器上指定它时,它定义要为返回的实体返回哪个视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.