我有一个POJO类扩展net.sf.gilead.pojo.gwt.LightEntity。我无法使用com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(obj)将POJO对象序列化为JSON字符串。我收到了这个错误
com.fasterxml.jackson.databind.JsonMappingException:
Direct self-reference leading to cycle
(through reference chain: com.example.MyClass["underlyingValue"])注意到LightEntity类具有以下方法:
public Object getUnderlyingValue() {
return this;
}发布于 2018-06-18 09:09:49
在您的MyClass类中尝试重写此方法并添加@JsonIgnore注释如何?
示例:
public class MyClass extends LightEntity {
@JsonIgnore
@Override
public Object getUnderlyingValue() {
return super.getUnderlyingValue();
}
}https://stackoverflow.com/questions/50905920
复制相似问题