springBoot 返回实体报错

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuxuchuan/article/details/79076386

<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Jan 16 16:27:34 GMT+08:00 2018</div><div>There was an unexpected error (type=Internal Server Error, status=500).</div><div>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: java.util.HashMap[&quot;key&quot;]-&gt;cn.ac.iscas.gz.cloud.business.domain.Canteen_$$_jvst4f2_14[&quot;handler&quot;]); 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: java.util.HashMap[&quot;key&quot;]-&gt;cn.ac.iscas.gz.cloud.business.domain.Canteen_$$_jvst4f2_14[&quot;handler&quot;])</div></body></html>
解决思路是,在实体上面新增如下注解:

@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })

如果是导致无线递归问题的话,可以用下面:

@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler","historyArcticlesLinkMapping"})


添加如下注解,使得所有类同时生效

@Bean
public ObjectMapper myMapper() {
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}

猜你喜欢

转载自blog.csdn.net/xuxuchuan/article/details/79076386