Returned json unexpected, has "links" spelled as "_links" and structure different, in Spring hateoas Returned json unexpected, has "links" spelled as "_links" and structure different, in Spring hateoas spring spring

Returned json unexpected, has "links" spelled as "_links" and structure different, in Spring hateoas


Spring Boot now (version=1.3.3.RELEASE) has a property that controls the output JSON format of the PagedResources.

Just add the following config to your application.yml file:

spring.hateoas.use-hal-as-default-json-media-type: false

if you need the output to be like (based on question):

{  "productId" : 1,  "name" : "2",  "links" : [    {      "rel" : "self"      "href" : "http://localhost:8080/products/1"    }  ]}

Edited:

By the way, you only need @EnableSpringDataWebSupport annotation in this way.


Another option would be to disable the whole hypermedia auto-configuration feature (this is how it's done in one of the spring-boot + REST examples here):

@EnableAutoConfiguration(exclude = HypermediaAutoConfiguration.class)

As far as I know, HypermediaAutoConfiguration doesn't really do much except for configuring HAL, so it should be perfectly fine to disable it.


If you have HAL available it will be selected for you by spring boot (and "_links" is what you get with HAL). You should be able to @EnableHypermediaSupport manually to override the defaults.