springBoot 返回实体报错

<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);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值