问题描述
这是我的产品类别
@Entity
public class Product {
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="listingGroup_id")
@JsonBackReference
public ListingGroup listingGroup;
这是我的groupProduct类
and here is my groupProduct class
@Entity
public class GroupProduct {
@OneToMany(mappedBy = "listingGroup", fetch = FetchType.EAGER)
@JsonManagedReference
Set<Product> products;
GAOL :
GAOL:
- 当我查询产品时,我想要带有ProductGroup的产品(ProductGroup不应再次序列化其中的产品)
- 当我查询GroupProduct时,我想要里面的产品(没有这些产品列表,每个列表又包括GroupProduct)
- When I query for product, I want product with ProductGroup(ProductGroup should not serialize again the products inside)
- When I query GroupProduct, I want the products inside (without these list of products each including again the GroupProduct)
已经尝试
ALREADY TRIED
-
JsonBackReference,JsonManagedReference:
JsonBackReference, JsonManagedReference:
GroupProduct一切正常,但是
The GroupProduct get everything fine, but
问题:反序列化的产品不包含该组产品:{id:1,... groupProduct:null}
Problem : the deserialized products does not contain the groupProduct : {id: 1, ... groupProduct: null}
JsonIdentityInfo:我不再能够反序列化对象java.lang.IllegalArgumentException:未找到类型为...的返回值的转换器.
JsonIdentityInfo : I am not able anymore to deserialize the objectsjava.lang.IllegalArgumentException: No converter found for return value of type...
环境
Environment
- 弹簧靴1.5.8
- 休眠5.0.12
- 'jackson-annotations',版本:'2.8.0'
- 'jackson-databind',版本:'2.8.7'
推荐答案
我认为您需要 @ JsonIgnoreProperties 注解,如下所示:
I think you need @JsonIgnoreProperties annotation, like this:
@JsonIgnoreProperties("products")
public ListingGroup listingGroup;
或类似这样:
@JsonIgnoreProperties("listingGroup")
Set<Product> products;
或两者都有.
这篇关于如何与渴望的双方反序列化一对多关系而不会陷入无限的反序列化循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!