title: Jackson (de)serializing object as its id
body: <p>Given POJO:</p>
  
  <pre><code>@XmlRootElement
  public class Categories implements Serializable {
      private int id;    
      private String name;
  
      private Categories parent;
  
      // ....    
  
  }
  </code></pre>
  
  <p>I'd like to serialize it to following json:</p>
  
  <pre><code>{ id: 1, name: "some name", parent: 5 }
  </code></pre>
  
  <p>So, main challenge here is to represent parent object as its id. Same thing i want
  for deserialization.</p>
  
  <p>I scannned rather large Jackson wiki and did not found anything that allowed
  to accomplish this without writing plethora of custom code.
  I think this is pretty common task and solution shold be somewhere nearby.</p>
  
  <p>Also it would be nice if solution will allow to customize null value cases.</p>
  
  <p><strong>UPD:</strong></p>
  
  <p>Now trying to use <code>XmlTypeAdapter</code> approch, not happy with it btw, because i need to write TypeAdapter
  for everyy single type i have and all they going to contain almost the same code:</p>
  
  <pre><code>public class CategoriesTypeAdapter extends XmlAdapter&lt;Integer, Categories&gt; {
  
      @Inject
      CategoriesFacade dao;
  
      @Override
      public Categories unmarshal(Integer v) throws Exception {
          return dao.find(v);
      }
  
      @Override
      public Integer marshal(Categories v) throws Exception {
          return v.getId();
      }
  }
  </code></pre>
  
  <p>Change in Categories.java:</p>
  
  <pre><code>    @XmlJavaTypeAdapter(CategoriesTypeAdapter.class)
      private Categories parent;
  </code></pre>
  
  <p><strong>UPD1:</strong></p>
  
  <p>And this is also not worked for me, at least deserializing now always return null in place of object, no idea how to debug this :
  For this JSON:</p>
  
  <pre><code>{ id: 1, name: "test", parent: 5 }
  </code></pre>
  
  <p>I get parent always null now:</p>
  
  <pre><code>Categories{categoryId=1, name="test", parentId=null}
  </code></pre>
  
  <p><strong>UPD2:</strong></p>
  
  <p>I found that htere is my fail in tis isssue, just did not setup things propertly, and my web.xml was lacking this entry:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
          &lt;param-value&gt;com.neopod.rest&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;com.sun.jersey.api.json.POJOMappingFeature&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/servlet&gt;
  </code></pre>