title: JSON Serialization of pojos with child objects
body: <p>Let's say I have a restful webservice with the following interfaces:</p>
  
  <pre><code>GET /some/parent
  </code></pre>
  
  <p>This will return something like</p>
  
  <pre><code>[
      {
          urn: "/some/parent/1",
          name: "parent1",
          children: [ "/some/child1", "/some/child2" ]
      },
      {
          urn: "/some/parent/2",
          name: "parent2",
          children: [ "/some/child3", "/some/child4" ]
      }
  ]
  </code></pre>
  
  <p>and, i've got </p>
  
  <pre><code>GET /some/parent/{id}
  </code></pre>
  
  <p>that return something like this:</p>
  
  <pre><code>{
      urn: /some/parent/1,
      name: parent1,
      children: [
          {
              urn: "/some/child1",
              name: "child1"
          },
          {
              urn: "/some/child2",
              name: "child2"
          }
      ]
  }
  </code></pre>
  
  <p>So, when requesting a list of parents, the json representations for every parent will be list with the child urns. When requesting a specific parent resource the json representation will contain a list of child json representations.</p>
  
  <p>With jersey the common way would be to define two simple java pojos and a simple Resource:</p>
  
  <pre><code>public class Parent {
      private String id;
      private String name;
      private List&lt;String&gt; childIds;
      ...
      @JsonIgnore
      public String getId()...
      @JsonProperty
      public String getUrn()...
  }
  
  public class Child {
      private String id:
      private String name;
      ...
      @JsonIgnore
      public String getId()...
      @JsonProperty
      public String getUrn()...
  }
  
  @Path("/some/parent")
  @Produces(MediaType.APPLICATION_JSON)
  public class ParentResource() {
      @GET
      public List&lt;Parent&gt; findAll() {
          List&lt;Parent&gt; result = // some database query call
          return result;
      }
  
      @GET
      @Path("{id}")
      public Parent find(@PathParam("id") String id) {
          Parent parent = // some database call
          return parent;
      }
  }
  </code></pre>
  
  <p>How can I inject the child urns/objects in the above scenarios? Are there any best practices? How do you solve this? </p>
  
  <p>Thanks.</p>