1

我有一个 POJO 类扩展net.sf.gilead.pojo.gwt.LightEntity. 我无法使用 .将 POJO 对象序列化为 JSON 字符串com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(obj)。我收到此错误

com.fasterxml.jackson.databind.JsonMappingException: 
Direct self-reference leading to cycle 
(through reference chain: com.example.MyClass["underlyingValue"])

注意到 LightEntity 类有这个方法:

public Object getUnderlyingValue() {
   return this;
}
4

1 回答 1

2

如何尝试在您的MyClass类中覆盖此方法并添加@JsonIgnore注释?

例子:

public class MyClass extends LightEntity {

    @JsonIgnore
    @Override
    public Object getUnderlyingValue() {
        return super.getUnderlyingValue();
    }

}
于 2018-06-18T09:09:49.197 回答