com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.learnkeeper.shared.entities.RootBook["permissionRef"]->com.googlecode.objectify.impl.ref.LiveRef["key"]->com.googlecode.objectify.Key["root"])
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter._handleSelfReference(BeanPropertyWriter.java:781)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:569)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3385)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2779)
3条答案
按热度按时间isr3a4wc1#
正如@Zutty所建议的:
在Jackson中新增了ObjectMapper().writeValueAsString(对象)
我试过了,但是得到一个com.fasterxml.Jackson.databind.jsonMappingException
当使用new Gson().toJson(Object)时,我会得到一个很好的Json:
其他信息:我希望记录所有Java对象都实现了java.io.Serializable
bq9c1y662#
takipi的工作人员对几个json解析器进行了comparison性能测试,包括gson和Jackson,结果发现这取决于被解析的文档类型,Gson处理小文档的速度更快,jackson处理大文档的速度更快,第三种选择json.simple在大文档和小文档上都提供了更一致的性能。
r1zk6ea13#
还有几个不同之处需要补充:
属性访问器.GETTER,可见性. PROTECTED_AND_PUBLIC);
请参见示例:
输出: