Springmvc Error: HTTP Status 500 – Could not write content: No serializer

HTTP Status 500 – Could not write content: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.pbc.rsms.entity.UserInfo_$$_jvstcc6_0[“handler”]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.pbc.rsms.entity.UserInfo_$$_jvstcc6_0[“handler”])

Reason: 

The problem is that with load method you get just a proxy but not the real object. The proxy object doesn’t have the properties already loaded so when the serialization happens there are no properties to be serialized. With the get method you actually get the real object, this object could in fact be serialized.

Method 1:

Add to the entity class generated by hibernate.

@JsonIgnoreProperties({“hibernateLazyInitializer”, “handler”})

Method 2: 

load to get

I think that the problem is the way that you retrieve the entity.

Maybe you are doing something like this:

Person p = (Person) session.load(Person.class, new Integer(id));
Try using the method get instead of load

Person p = (Person) session.get(Person.class, new Integer(id));
The problem is that with load method you get just a proxy but not the real object. The proxy object doesn’t have the properties already loaded so when the serialization happens there are no properties to be serialized. With the get method you actually get the real object, this object could in fact be serialized.

Similar Posts: