title: Serialize parent-child object
body: <p>I have a REST service, built with spring-mvc:</p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"&gt;
      &lt;property name="contentType" value="text/plain"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;  
      &lt;property name="messageConverters"&gt;  
          &lt;util:list id="beanList"&gt;  
              &lt;bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/&gt;  
          &lt;/util:list&gt;  
      &lt;/property&gt;  
  &lt;/bean&gt;  
  </code></pre>
  
  <p>To avoid circular references in serialization I annotate the object as follows:</p>
  
  <pre><code>class Parent implements Serializable {
      int parent_id;
      @JsonManagedReference
      private List&lt;Child&gt; children; 
  }
  
  class Child implements Serializable {
      int child_id;
      @JsonBackReference
      private Parent parent;
  }
  </code></pre>
  
  <p>My REST service exposes two "methods" that gets a parent and a child, respectively:</p>
  
  <pre><code>@RequestMapping(value = "/parent/{id}", method = RequestMethod.GET)
  @ResponseBody public Parent getParent(@PathVariable int id , Model model) {
      Parent parent = myManager.getParent(id);
      return parent;
  }
  
  @RequestMapping(value = "/child/{id}", method = RequestMethod.GET)
  @ResponseBody public Child getChild(@PathVariable int id , Model model) {
      Child child = myManager.getChild(id);
      return parent;
  }
  </code></pre>
  
  <p>The first method, getParent, works as expected and returns a Parent, complete with all children, but the second method, getChild, returns a single child, which does <strong>not</strong> have any reference back to it's parent.</p>
  
  <pre><code>json for parent: {"parent_id": 1, "children": [{"child_id":1},{"child_id":2}]}    
  json for child: {"child_id":1}
  </code></pre>
  
  <p>So my question is, how do I set up serialization, so that getChild returns some sort of reference to it's parent object?</p>