【问题标题】:JsonMappingException: Direct self-reference leading to cycle (through reference chain: MyClass["underlyingValue"])JsonMappingException:直接自引用导致循环(通过引用链:MyClass["underlyingValue"])
【发布时间】:2018-11-27 02:10:00
【问题描述】:

我有一个扩展 net.sf.gilead.pojo.gwt.LightEntity 的 POJO 类。我无法使用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;
}

【问题讨论】:

    标签: java gwt objectmapper json-serialization


    【解决方案1】:

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

    例子:

    public class MyClass extends LightEntity {
    
        @JsonIgnore
        @Override
        public Object getUnderlyingValue() {
            return super.getUnderlyingValue();
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2021-08-28
      • 2017-07-27
      • 1970-01-01
      相关资源
      最近更新 更多