title: Spring Data Rest - _links
body: <p>Edit 14/08/14 13:29</p>
  
  <p>My next conclusion is that the hal+json format produced from my @RepositoryRestResource CrudRepository is incorrect.</p>
  
  <p>The tutorial (<a href="http://spring.io/guides/gs/accessing-data-rest/" rel="nofollow">http://spring.io/guides/gs/accessing-data-rest/</a>) shows the output of a hypermedia Rest JPA entity as: (please note there is no "rel" element, and "links" is not an array)</p>
  
  <pre><code>{
     "_links" : {
         "people" : {
             "href" : "http://localhost:8080/people{?page,size,sort}"
         }
     }
   }
  </code></pre>
  
  <p>However, the reference docs (<a href="http://docs.spring.io/spring-data/rest/docs/1.1.x/reference/html/intro-chapter.html" rel="nofollow">http://docs.spring.io/spring-data/rest/docs/1.1.x/reference/html/intro-chapter.html</a>) show that the output should be:</p>
  
  <pre><code>{
      "links" : [ {
          "rel" : "customer",
          "href" : "http://localhost:8080/customer"
        }, {
           "rel" : "profile",
           "href" : "http://localhost:8080/profile"
        }
   }
  </code></pre>
  
  <p>Does anyone know why this is?</p>
  
  <p>=====================================</p>
  
  <p>Edit 14/08/14: I have taken my debugging a step further. By providing my own implementation of a org.springframework.hateoas.ResourceSupport class, which inspects the json for "_links" rather than "links" I get a step further. The error is:</p>
  
  <blockquote>
    <p>"Can not deserialize instance of java.util.ArrayList out of START_OBJECT token ..... through reference chain: com.ebs.solas.admin.test.SolicitorDTO[\"_links\"]"</p>
  </blockquote>
  
  <p>This is because the org.springframework.hateoas.ResourceSupport class seems to require that the links attribute be a json array. And by default the json+hal output produced by Spring Data for a Rest Entity does not produce an array (there are no square brackets):</p>
  
  <pre><code>"_links" : {
    "self" : {
      "href" : "http://localhost:9090/solas-admin-data-api/solicitorFirms/Fxxx"
    },
    "solicitors" : {
      "href" : "http://localhost:9090/solas-admin-data-api/solicitorFirms/Fxxx/solicitor
    }
  }
  </code></pre>
  
  <p>Hopefully someone from the Spring forums could help me here. </p>
  
  <p>==============================================</p>
  
  <p>please see an outline of my Spring Data repository code:</p>
  
  <pre><code>@RepositoryRestResource
      public interface SolicitorFirmRepository extends CrudRepository&lt;SolicitorFirm, String&gt; {
  }
  
  @Entity
  @RestResource
  @Table(name="XXXX", schema = "XXX")
  public class SolicitorFirm implements Serializable {
  }
  </code></pre>
  
  <p>This successfully generates the following hateoas resource:</p>
  
  <pre><code>{
  "firmNumber" : "FXXXX",
  "solicitorType" : "r",
  "companyName" : "XXXX",
  "address1" : "XXXX",
  "address2" : "XXX",
  "address3" : "XXX",
  "address4" : null,
  "phoneNumber" : "XXXXX",
  "faxNumber" : "XXXXX",
  "county" : "OY",
  "_links" : {
      "self" : {
          "href" : "http://localhost:9090/solas-admin-data-api/solicitorFirms/XXXX"
      },
      "solicitors" : {
          "href" : "http://localhost:9090/solas-admin-data-api/solicitorFirms/XXXX/solicitors"
      }
   }
  </code></pre>
  
  <p>HOWEVER, when i define a DTO for clientside/controller use:</p>
  
  <pre><code>import org.springframework.hateoas.ResourceSupport;
  public class SolicitorFirmDTO extends ResourceSupport {
     .....
  }
  </code></pre>
  
  <p>and use the following code</p>
  
  <pre><code>RestTemplate rt = new RestTemplate();
  String uri = new String("//xxxxx:9090/solas-admin-data-api/solicitors/Sxxxxx");
  SolicitorFirmDTO u = rt.getForObject(uri, SolicitorFirmDTO.class, "SXXXX");
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field   "_links" (class com.ebs.solas.admin.test.SolicitorFirmDTO), not marked as ignorable (7 known properties: xx])  </p>
  </blockquote>
  
  <p>For some reason the json produced by Spring Data Rest adds the entity links under  <code>_links</code> while the HATEOAS resource superclass expects <code>links</code>?</p>
  
  <p>Can any one help? is this a version issue or do I need some extra configuration to map <code>_links</code> to <code>links</code></p>
  
  <p>I have tried <code>MappingJackson2HttpMessageConverter</code> and various media types <code>application/json+hal</code> to no avail.</p>