how to deserialize one to many relationship with b

2019-07-10 04:49发布

here is my Product class

@Entity
public class Product {

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="listingGroup_id")
    @JsonBackReference
    public ListingGroup listingGroup;

and here is my groupProduct class

@Entity
public class GroupProduct {

    @OneToMany(mappedBy = "listingGroup", fetch = FetchType.EAGER)
    @JsonManagedReference
    Set<Product> products;

GAOL:

  1. When I query for product, I want product with ProductGroup (ProductGroup should not serialize again the products inside)
  2. When I query GroupProduct, I want the products inside (without these list of products each including again the GroupProduct)

ALREADY TRIED

  1. JsonBackReference, JsonManagedReference:

    The GroupProduct get everything fine, but

    Problem : the deserialized products does not contain the group Product : {id: 1, ... groupProduct: null}

  2. JsonIdentityInfo : I am not able anymore to deserialize the objects java.lang.IllegalArgumentException: No converter found for return value of type...

Environment

  • spring boot 1.5.8
  • hibernate 5.0.12
  • 'jackson-annotations', version: '2.8.0'
  • 'jackson-databind', version: '2.8.7'

1条回答
闹够了就滚
2楼-- · 2019-07-10 05:32

I think you need @JsonIgnoreProperties annotation, like this:

@JsonIgnoreProperties("products")
public ListingGroup listingGroup;

or like this:

@JsonIgnoreProperties("listingGroup")
Set<Product> products;

or both.

查看更多
登录 后发表回答