问题
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:
- 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:
The GroupProduct get everything fine, but
Problem : the deserialized products does not contain the group Product : {id: 1, ... groupProduct: null}
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:
I think you need @JsonIgnoreProperties annotation, like this:
@JsonIgnoreProperties("products")
public ListingGroup listingGroup;
or like this:
@JsonIgnoreProperties("listingGroup")
Set<Product> products;
or both.
来源:https://stackoverflow.com/questions/49530737/how-to-deserialize-one-to-many-relationship-with-both-eager-sides-without-ending