JSON serialization format is all the rage these days when it comes to making Ajax calls from the browser. And
Jackson JSON-processor is probably the best and most popular serializer written in Java for converting domain objects into JSON.
Hibernate is, of course, the most popular object-relational mapping framework. And the problem is that those
(
Read more... )
Comments 33
Is there a way to make it work only with already initialized entities and not attempt to initialize anything (or am I wrong and it doesn't)? I'd like the service to decide what to initialize and when
Can it be done? (or did I miss something and you already do that) :)
Thanks again
Reply
Reply
Reply
My problem now is with Generics, and I seen somewhere that Jackson 1.8 should take care of it, so I downloaded it but now it broke your code :) it doesn't compile... I tried to do some quick fixes here, but besides passing nulls in new introduced parameters to buildCollectionSerializer and buildMapSerializer I have no clue what to do
Is there a chance you have a 1.8 compatible version by any chance? ;)
Reply
Reply
Reply
The lazy load problem while using "mapper.writeValueAsString()" was solved using the above solution.
But the problem we are facing right now is like this -
We use javax enetitymanager for making DB transactions.
We create an entity which has bi-directional associations (using em.persist(entity)). The record gets saved very nicely.
We load the newly saved record immediately, but we get infinite recursion problem :
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:212)
What could be the way to avoid this problem ??
We understand this is due to bi-directional dependency and we don't want to use @JsonIgnore also.
Reply
Reply
But have another challenge now. The pojos are auto generated using hbm2java goal of hibernate-tools maven plugin with reverse engineering, and that won't generate these custom annotations (may be I am not aware of how to do this.) :(
Reply
Reply
My other problem is that the model POJO's are auto-generated via HBM files as it has been reported by the other user above. So are there any plans in future to make this solution work probably by providing some exclusion rules explicitly on the objectmapper ? instead of the @JsonIgnore annotation? (I have seen some JSONGenerators providing this sort of exclusion rules, so just curious.)
However for now its not a very painful exercise as the list of HBMs are only handful and I can go and modify these POJOs myself. But can see this becoming a bottleneck when the list grows huge and each subsequent code generation could become painful.
Overall your solution is the best I have searched so far! Thank You!
Reply
Leave a comment