对象是通过hibernate 查询的一对一双向关系的对象:
解析代码:
Employee e = employeeService.findOne(2); System.out.println(e); String str = JSON.toJSONString(e, SerializerFeature.DisableCircularReferenceDetect); System.out.println(str);
报错:
java.lang.StackOverflowError at com.alibaba.fastjson.serializer.SerializerFeature.isEnabled(SerializerFeature.java:148) at com.alibaba.fastjson.serializer.SerializeWriter.isEnabled(SerializeWriter.java:130) at com.alibaba.fastjson.serializer.JSONSerializer.isEnabled(JSONSerializer.java:335) at com.alibaba.fastjson.serializer.JavaBeanSerializer.isWriteAsArray(JavaBeanSerializer.java:293) at Serializer_2.write1(Unknown Source) at Serializer_2.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) at Serializer_1.write1(Unknown Source) at Serializer_1.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) at Serializer_2.write1(Unknown Source) at Serializer_2.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) at Serializer_1.write1(Unknown Source) at Serializer_1.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) at Serializer_2.write1(Unknown Source) at Serializer_2.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) at Serializer_1.write1(Unknown Source)
主外键关联进入死循环了,建议tojson的时候注解一下employee不进行序列化,具体在Employee实体中的<spanstyle="font-size:13.3333px;">employee属性上加<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">@JSONField(serialize=false)注解,如果不行请自行搜索其他方法。你这个问题的更本是自关联进入了死循环。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。