title: Jackson - infinite loops deserializing
body: <p>I am using jackson to deserialize following json content:</p>
  
  <pre><code>{
   "contacts": [
      {
        "localId": 45,
        "serverId": 0,
        "numbers": [
          "1111",
          "2222"
        ]
      },
      {
        "localId": 11,
        "serverId": 0,
        "numbers": [
          "5555"
        ]
      }
     ]
  }
  </code></pre>
  
  <p>My Java classes are </p>
  
  <pre><code>public class Contacts implements Serializable {
  
      private List&lt;Contact&gt; contacts;
  
      ... public Getter and Setter here
  
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>@JsonSerialize(using = ContactSerializer.class)
  public class Contact implements Serializable {
  
      public long server_id;
      public long local_id;
      public List&lt;String&gt; numbers;
  
       ... public Getter and Setter here
  }
  </code></pre>
  
  <p>There is no reference from Contact to Contacts. There are some additional attributes in Contact which are not serialized on the way to the server (request) and not send back from the server (response). I excluded them by  using  @JsonIgnore.
  I receive the json mentioned above as answer from the server. But when deserializing it there will be a infinite loop and the programm terminates.
  I tried to use a deserializer for Contact, but it had the same result. It ended in a infinite loop inside Contact.</p>
  
  <p>EDIT: The method call from the app:</p>
  
  <pre><code> ObjectMapper mapper = new ObjectMapper();
   Contacts c = mapper.readValue(result.getResult(), Contacts.class);
  </code></pre>
  
  <p>EDIT: The Serializer</p>
  
  <pre><code>public class ContactSerializer extends StdSerializer&lt;Contact&gt; {
  
      protected ContactSerializer() {
          super(Contact.class);
      }
  
      @RequiresApi(api = Build.VERSION_CODES.N)
      @Override
      public void serialize(Contact value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
  
          jgen.writeStartObject();
  
          jgen.writeNumberField(Contact.COLUMN_LOCAL_ID, value.getLocalId());
          jgen.writeNumberField(Contact.COLUMN_SERVER_ID, value.getServerId());
          jgen.writeObjectField(Contact.COLUMN_NUMBERS, value.getNumbers());
  
          jgen.writeEndObject();
      }
  }
  </code></pre>