fastjson 对象转json string 解决循环引用报错(溢出)
对象是通过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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论