On Sun, Apr 19, 2020 at 11:05 AM 'Thø Jø' via jackson-user <[email protected]> wrote: > > Hey, > > I currently resolve circulare dependencies with JsonIdentityInfo and new > generated UUID. I would like use existing primary key. My problem is that my > PK is a composite key of normally two attributes (String or int) "id" and > "version". I cannot change the classes because of 3rd party lib. I can only > use Mixin or something else. > > public class Parent { > // this is my identiy composite key > ParentPK pk; > String bez; > Date created; > Child child; > > // constructor, getter and setter > } > > public class ParentPK { > int parentId; > int version; > > // constructor, getter and setter > } > > public class Child { > String childId; > Parent parent; > > // constructor, getter and setter > } > > How can I use my ParentPK as identity in Jackson? I've tried to use > JsonIdentityInfo in combination with virtual attributes and JsonAppend. But > his won't work because the property does not exist in POJO. In my mind I've > several ideas as solutions but don't know whether they can implemented in > Jackson: > > Use existing ParentPK JSON representation e.g. {id:"99", version:"v1"} as > JsonIdentityInfo and use equals method in Jackson to compare objects will be > the best because no additional attribute will be added to parent. But I don't > know whether custom objects are possible as identity? > Create virtual String attribute "compositeKey" e.g. "99-v1 and use it as > JsonIdentityInfo. But the virtual attribute via JsonAppend cannot be used in > combination with JsonIdentityInfo. > > > Have anyone an idea to implement this?
Unfortunately `@JsonIdentityInfo` was designed with the assumption that Ids are always scalars (Strings or possibly integers), so there is no support for such composite keys. There is a work-around for specific case of "boxed" single-property JSON object to support a json convention/standard (name of which escapes me now), but nothing beyond that. But maybe someone else has written something for "full Object" use case. Underlying components of identity handling might still be usable. -+ Tatu +- -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10i6FXytzUnBgxBA%3DMNtvHb8_Zv5PW83O7yfXg5QiyD1gg%40mail.gmail.com.
