json, hibernate and limited serialization
I am playing with a l开发者_运维问答ittle web-app that is planned to have a presentation layer delivering json-encoded data. This app is backed by a couple of spring-services that fetch their data from hibernate.
As I read in a spring-mvc-ajax article, spring-mvc is able to serialize pojos to json. What I want to do is to transmit retrieved objects in json.
My datamodel atm looks like that:
Class A
[...]
List<Class B> list;
Class B
[...]
List<Class C> list;
Class C
String content;
All of these classes are mapped to a db with hibernate.
The problem I see now is that hibernate (driven by the json-conversion) traverses the object tree and retrieves all objects referenced by Class A. And spring-mvc serialises them all to json. And that's not what I want, as this can be a lot of data.
I would prefer to store lists of ids (instead of references) - so that only ids are serialized - but haven't found how this can be done with hibernate.
How can I do that right? C.
You should transform your Hibernate POJOs into an intermediate object graph, dedicated to JSON serialization.
精彩评论