@Entity
public Product {
@Id
public int id;
public String name;
@ManyToOne(cascade = {CascadeType.DETACH} )
Category category
@ManyToMany(fetch
Another approach is to use @JsonCreator factory method if you can modify your Entity
private class Product {
@JsonProperty("category")
private Category category;
@JsonProperty("secondaryCategories")
private List secondaryCategories;
}
private class Category {
@JsonProperty("id")
private int id;
@JsonCreator
public static Category factory(int id){
Category p = new Category();
p.id = id;
// or some db call
return p;
}
}
Or even something like this should also work
private class Category {
private int id;
public Category() {}
@JsonCreator
public Category(int id) {
this.id = id;
}
}