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
I tried your approach handling.
First the the class HibernateAwareSerializerFactory won't compile for me. I had either to change the two line containing config.introspect(type.getRawClass()); to config.introspectClassAnnotations(type.getRawClass()); or to config.introspect(type);
Then the class get's compiled without any errors. I tried to use the Mapper in my spring app using:
However I'm still running in:
org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role ...
Any ideas?
regards,
Frank
Reply
Reply
wow that was fast :-). Yes you are right, using the 1.5.7er version it compiles without any failures. However I'm getting the same failure concerning lazy loading. The HibernateAwareObjectMapper constructor get's called during startup, but not the HibernateAwareSerializerFactory during a request. You can find my spring config here: http://pastebin.com/k8n86ABe.
thanks for you help,
Frank
Reply
Reply
Reply
Reply
Reply
I have modified filterBeanProperties to exclude those getMethods whose Field is marked Transient with Transient java keyword.
/**
* The purpose of this method is to filter out {@link Transient} properties of the bean
* from JSON rendering.
*/
@Override
protected List filterBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc,
List props) {
//filter out standard properties (e.g. those marked with @JsonIgnore)
props = super.filterBeanProperties(config, beanDesc, props);
filterInstrumentedBeanProperties(beanDesc, props);
//now filter out the @Transient ones as they may trigger "lazy" exceptions by
//referencing non-initialized properties
List transientOnes = new ArrayList //BeanUtils and AnnotationUtils are utility methods that come from ( ... )
Reply
Leave a comment