No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer解决方法

org.springframework.http.converter.HttpMessageNotWritableException:
 Could not write JSON: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 
 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) 
 (through reference chain: java.util.ArrayList[2]->com.sohu.appmonitor.config.model.AppProject["authGroup"]->
 com.sohu.appmonitor.auth.model.AuthGroup_$$_javassist_11["handler"]); 
 nested exception is org.codehaus.jackson.map.JsonMappingException:  No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 
 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) 

  (through reference chain: java.util.ArrayList[2]->com.sohu.appmonitor.config.model.AppProject["authGroup"]->com.sohu.appmonitor.auth.model.AuthGroup_$$_javassist_11["handler"])java


解决方法:spring

1. 配置文件:json

<mvc:annotation-driven>
mvc

<mvc:message-converters>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper">
<bean class="com.sohu.appmonitor.frame.util.HibernateObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
</bean>
</property>
</bean>
</property>
</bean>
app

<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean
class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean
class="org.springframework.http.converter.ResourceHttpMessageConverter" />
</mvc:message-converters>
spa

</mvc:annotation-driven>
hibernate

2.添加以下类:code

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
orm

public class HibernateObjectMapper extends ObjectMapper{
public HibernateObjectMapper() {
disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
}
}
it