2

I am building a web service where my clients can only accept application/json as a response. But Spring Hateoas seems to not respect my produces in the GetMapping annotation, and always returns HAL.

I have already tried: putting

spring.hateoas.useHalAsDefaultJsonMediaType=false

also in kebab case:

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

Also putting

spring.data.rest.defaultMediaType=application/json

I have tried putting produces=application/json in the @GetMapping annotation and in the controller.

We have also tried implementing:

SpringRestConfiguration implements RepositoryRestConfigurer...

None of these things worked.

Our spring boot version is 2.0.8

We expect the response json to be in application/json without the "_embedded" for a list of resources.

Ben Yan
  • 21
  • 1
  • Hi Welcome to StackOverflow aka. "SO" Please see the help section as this will guide you in getting more support from us in the community. https://stackoverflow.com/help/ Best wishes on your endeavors! Cheers! – JayRizzo Jun 24 '19 at 23:42
  • Possible duplicate of [Spring MVC 3: return a Spring-Data Page as JSON](https://stackoverflow.com/questions/16790371/spring-mvc-3-return-a-spring-data-page-as-json) – JayRizzo Jun 24 '19 at 23:43
  • Hi @JayRizzo, perhaps I did not ask this question properly but those articles did not really help. I am able return a JSON when "links" is an array of objects. But in the case where I need "links" to be an object of objects, it seems like HAL format is the only way to accomplish this. Is there a way to send back a JSON while links is an object of objects? Thanks! – Ben Yan Jun 25 '19 at 02:07
  • Hi @ben-yan, is this more of what you are looking for? https://stackoverflow.com/a/53222580/1896134 or https://stackoverflow.com/a/25715239/1896134 or maybe https://stackoverflow.com/a/44739243/1896134 – JayRizzo Jun 25 '19 at 21:13

0 Answers0