title: REST HATEOAS: How to serialize nested resources (with Spring HATEOAS)?
body: <p>I use Spring HATEOAS for creating a REST HATEOAS API in my application. It works well so far, but I'm stuck when it comes to nested resources. What is the right approach for mapping a class hierarchy like this to a REST HATEOAS resource:</p>
  
  <pre><code>public class MyEntity {
  
      private int id;
  
      private List&lt;ChildEntity&gt; children;
  
  }
  
  
  public class ChildEntity {
  
      private int id;
  
      private AnotherEntity entity;
  
  }
  
  
  public class AnotherEntity {
  }
  </code></pre>
  
  <p>I created <a href="http://docs.spring.io/spring-hateoas/docs/0.19.0.RELEASE/api/org/springframework/hateoas/Resource.html" rel="nofollow">Resource</a> classes for all of this entities, but when serialising MyEntity, all contained entities get serialized as POJOs although I need them to be serialized as resources too (with links etc). Is there a way to add a resource to a parent resource (and not using the <a href="http://docs.spring.io/spring-hateoas/docs/0.19.0.RELEASE/api/org/springframework/hateoas/Resources.html" rel="nofollow">Resources</a> class)? Or do I have to add a @JsonIgnore to children and then manually add the children as resources in my <a href="http://docs.spring.io/spring-hateoas/docs/0.19.0.RELEASE/api/org/springframework/hateoas/ResourceAssembler.html" rel="nofollow">ResourceAssembler</a>? Wouldnt it then make more sense to use <a href="http://docs.spring.io/spring-hateoas/docs/0.19.0.RELEASE/api/org/springframework/hateoas/ResourceSupport.html" rel="nofollow">ResourceSupport</a> instead of Resource? </p>