1

I have a POJO class extending net.sf.gilead.pojo.gwt.LightEntity. I am not able to serialize the POJO object to JSON string using com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(obj). I am getting this error

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

Noticed that the LightEntity class has this method:

public Object getUnderlyingValue() {
   return this;
}
Jayram Kumar
  • 682
  • 2
  • 16
  • 28

1 Answers1

3

How about to try to override this method in your MyClass class and add the @JsonIgnore annotation?

Example:

public class MyClass extends LightEntity {

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

}
pleft
  • 7,567
  • 2
  • 21
  • 45