title: Infinite Recursion when convert object to JSON using Jackson
body: <p>I have this class that I am using to store preferences for a tool. This class uses the toString() to convert itself to JSON. I am getting this infinite recursion error when I am converting the object to JSON, and I cannot figure out why. I do not have any circular references so it is confusing me a bit. Any help would be appreciated.</p>
  
  <p>Here is my class structure:</p>
  
  <pre><code>public class ToolPrefs
  {
     private boolean isFloating;
     private ToolPalettePlacement placement; //this is an enum
     private boolean isSelected;
     private int dockLocation;
     private Point dialogLocation;
     private Dimension dialogSize;
  
     public ToolPrefs(){}
  
     public boolean isFloating(){return isFloating; }
  
     public void setFloating(boolean floating){ isFloating = floating; }
  
     public ToolPalettePlacement getPlacement(){ return placement; }
  
     public void setPlacement(ToolPalettePlacement placement){ this.placement = placement;}
  
     public boolean isSelected(){ return isSelected;}
  
     public void setSelected(boolean selected){isSelected = selected;}
  
     public int getDockLocation(){return dockLocation;}
  
     public void setDockLocation(int dockLocation){this.dockLocation = dockLocation; }
  
     public Point getDialogLocation(){return dialogLocation;}
  
     public void setDialogLocation(Point dialogLocation){ this.dialogLocation = dialogLocation;}
  
     public Dimension getDialogSize(){ return dialogSize; }
  
     public void setDialogSize(Dimension dialogSize){this.dialogSize = dialogSize;}
  
  
     @JsonIgnore @Override
     public String toString()
     {
        String json;
        ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
        try
        {
           json = ow.writeValueAsString(this);
        }
        catch (IOException e)
        {
           e.printStackTrace();
           json = "";
        }
        return json;
     }
  }
  </code></pre>
  
  <p>Here is the exception snippet I am receiving:</p>
  
  <blockquote>
    <p>com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]->java.awt.Point["location"]...)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:518)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:117)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:504)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:117)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:504)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:117)
        at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
        at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:504)
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:117)</p>
  </blockquote>