title: Jackson JSON: Implementing a TypeIdResolver
body: <p>I'm currently working on designing base API to use static data in my application server and I choose Jackson as a way to serialize my data. The problem is that I don't want any nesting in the final JSON file so I end up with this :</p>
  
  <pre><code>@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
  public class Parent {
      public long id;
      public String name;
  
      @JsonIdentityReference(alwaysAsId = true)
      @JsonManagedReference
      public Set&lt;Child&gt; children = new HashSet&lt;&gt;();
  }
  
  @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
  public class Child {
      public long id;
      public String name;
  
      @JsonIdentityReference(alwaysAsId = true)
      @JsonBackReference
      public Parent parent;
  }
  
  public static class Registry {
      public Set&lt;Parent&gt; parents = new HashSet&lt;&gt;();
      public Set&lt;Child&gt; children = new HashSet&lt;&gt;();
  }
  </code></pre>
  
  <p>This works great for serializing, I get something like :</p>
  
  <pre><code>{
      "parents" : [ {
          "id" : 1,
          "name" : "DADDY",
          "children" : [ 1, 2 ]
      } ],
      "children" : [ {
          "id" : 1,
          "name" : "JUNIOR"
      }, {
          "id" : 2,
          "name" : "JUNIOR'S SISTER"
      } ]
  }
  </code></pre>
  
  <p>But now, I want to deserialize it but then unfortunately an exception is thrown : <code>Could not resolve Object Id [2] (for [simple type, class org.photon.Main$Child])</code>. After some research, I was told that I have to implement a custom type id resolver but I could not do anything because of the lack of resource. I would like to tell Jackson how to get the instances of Parent to children and instances of Child to parents when deserializing Registry.</p>
  
  <p>Do you know how I can fix that or is there any other way to do it ?</p>