今天用ajax返回json格式的时候后台能查询出数据只是再返回到ajax中的时候报500Internal Server Error,用火狐具体调试了一些错误信息,一下是部分错误信息:
nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializerfound for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discoveredto create BeanSerializer (to avoid exception,disable SerializationConfig.SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.tgb.entity.CardInfo["cardPersonalInfo"]->com.tgb.entity.CardPersonalInfo_$$_javassist_15["handler"])
FAIL_ON_EMPTY_BEANS为空错误原因是我的实体CardInfo级联着实体CardPersonalInfo,实体CardPersonalInfo又级联CardInfo,我后台返回CardInfo JSON格式的时候报序列化错误,原因是CardInfo关联的CardPersonalInfo实体对象为空的时候就会报我的解决方案就是在CardPersonalInfo实体类上面加上一下注解:
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","operations","roles","menus"})
这样生成的JSON中不会产生多余的字段。原文链接:https://www.f2er.com/ajax/162795.html