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"])


解决方法:

1. 配置文件:

<mvc:annotation-driven>

<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>

<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>

</mvc:annotation-driven>

2.添加如下类:

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

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

你可能感兴趣的:(No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer解决方法)