I'm using Spring Roo which generated set of hibernate and FlexJSON classes.
I have entity called Location and entity called Comment. Location has many comments (1:M).
I'm trying to generate JSON object, which will, when deserialized and inserted reference existing Location object.
When I omit location field, everything is working fine, for example:
{
"date": 1315918228639,
"comment": "Bosnia is very nice country"
}
I don't know how to reference location field. I've tried following, but with little success:
{
"location": 10,
"date": 1315918228639,
"comment": "Bosnia is very nice country"
}
where location id is 10.
How can I reference location field in the JSON?
Edit: Added Comment entity:
@RooJavaBean
@RooToString
@RooJson
@RooEntity
public class Komentar {
private String comment;
@ManyToOne
private Location location;
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "M-")
private Date date;
}
I've solved issue by adding transient property.
@Transient
public long getLocationId(){
if(location!=null)
return location.getId();
else
return -1;
}
@Transient
public void setLocationId(long id){
location = Location.findLocation(id);
}