java - How to properly deserialize Jackson (JSON) together with Hibernate -


we have been having issues getting jackson , hibernate integrate each other. when decoupling objects hibernates proxy-magic, hibernate starts inserts when want update objects, since object deserialized using jackson detached hibernate. have solved temporarily defining our own builders

@jsondeserialize(builder = planbuilder.class) public class plan {     ... 

using pattern can control when need fetch objects database , merge updated json data (if doing update instance). can handle null values, @jsonignore attributes etc.

we did since if use @jsonignore on attribute hibernate thinks object being deserialized , updated doesnt have relations , removes them database not want, solve syncing in builders.

however, not feel robust or flexible solution. have else encountered problem , how did solve it?

best regards! / d

hibernate start performing insert's if object trying update doesn't have id field set. if jackson failing deserialize id correctly, hibernate insert object because doesn't know exists.

in current project, if need instance of particular object have id for, make rest call (say /user/) passing in user's id have on front end. controller picks call up, calls userservice hibernate session created (method annotated @transactional) calls userdao performs actual select. user object gets passed dao service layer controller, , because have controller annotated @responsebody automatically serialized json jackson.

if want pass object in created/updated, pass in using restful post or put. object serialized front-end json , passed in request body. controller has parameter annotated @requestbody gets jackson deserialise when received. call service layer , pattern follows example above.

the advantage of jackson , hibernate never have know other exists. jackson turns json object gets managed hibernate.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -