i using spring mvc rest controller perform simple crud operations on entities. i'm struggling little jackson trying figure out how implement @manytoone relationship. when jacskon serializes "inverse" side of relationship, omits "owning" property. heres @ code:
@entity public class competition { @id @generatedvalue(strategy = generationtype.auto) private long id; private string name; private string nameinurl; @manytoone(cascade = cascadetype.all) @jsonidentityreference(alwaysasid=true) @jsonbackreference(value="test") private sport sport; public long getid() { return id; } public void setid(long id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getnameinurl() { return nameinurl; } public void setnameinurl(string nameinurl) { this.nameinurl = nameinurl; } public sport getsport() { return sport; } public void setsport(sport sport) { this.sport = sport; } } @entity public class sport { @id @generatedvalue(strategy = generationtype.auto) private long id; private string name; private string nameinurl; @onetomany(cascade = cascadetype.all, mappedby="sport") @jsonmanagedreference(value="test") private set<competition> competitions = new hashset<competition>(); public long getid() { return id; } public void setid(long id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getnameinurl() { return nameinurl; } public void setnameinurl(string nameinurl) { this.nameinurl = nameinurl; } public set<competition> getcompetitions() { return competitions; } public void setcompetitions(set<competition> competitions) { this.competitions = competitions; } }
i ask how can achieve serializing competition entity in entirety, without omitting sport entity?
thanks, dave
well, according this answer (if understand right), @jsonbackreference
, @jsonmanagedreference
pair in serialization don't implies store whole object in json, id. when deserialize json obtain recursive connections without stackoverflow
. expected behavior (i think=)).
but if need pass in json whole objects, need remove @jsonbackreference
, @jsonmanagedreference
, pass @jsonignore
competitions
field in sport
class, lost recursive connection in deserialize.
also, can try write own deserializer sport
class recursion obtain.
i hope you.
Comments
Post a Comment