@Entity
public Product {
@Id
public int id;
public String name;
@ManyToOne(cascade = {CascadeType.DETACH} )
Category category
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH} )
Set<Category> secondaryCategories;
}
and this entity:
@Entity
public Category {
@Id
public int id;
public String name;
}
I would like to be able to send a POST with json
{ name: "name", category: 2, secondaryCategories: [3,4,5] }
from client-side
and be able to be deserialized like:
{ name: "name", category: {id: 2 }, secondaryCategories: [{id: 3}, {id: 4}, {id: 5}] }
in case it was sent as
{ name: "name", category: {id: 2 }, secondaryCategories: [{id: 3}, {id: 4}, {id: 5}] }
I would like it to still work as now
what kind of annotation and custom deserializer I need? Hopefully the deserializer can work for all possible objects that have id as a property
Thanks!
Edit
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…