Skip to content

should honor use-hal-as-default-json-media-type #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rainoko opened this issue Dec 22, 2016 · 13 comments
Closed

should honor use-hal-as-default-json-media-type #532

rainoko opened this issue Dec 22, 2016 · 13 comments

Comments

@rainoko
Copy link

rainoko commented Dec 22, 2016

Spring boot introduced configuration use-hal-as-default-json-media-type which helps fallback from hal format links. spring-hateoas should honor this otherwise it is not compatible with boot anymore.

@odrotbohm
Copy link
Member

There's nothing in Spring HATEOAS that it could honor here as it doesn't know anything about Spring Boot. When you say "anymore" can you please clarify what you mean by that? Has something worked before that now doesn't anymore? Would you mind getting a bit more precise on what works and what doesn't? Maybe through a test case/project?

@rainoko
Copy link
Author

rainoko commented Dec 23, 2016

I tried to migrate from 0.18 to 0.23 (0.22 had bug with context)
problem is that 0.23 registretes HAL support for jackson converter.

In general spring-boot autoconfiguration doing same thing but honors flag use-hal-as-default-json-media-type. This registration adds application/json as supported media type for jackson configuration and causing HAL format by default.
org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration

Now it seems that spring-hateoas doing it also in
org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar
But seems that I cant drive it or I'm not clever enough to drive it.

@rainoko
Copy link
Author

rainoko commented Mar 9, 2017

any news about this?

@rainoko
Copy link
Author

rainoko commented Jun 21, 2017

seems that issue not appears anymore.

@rainoko rainoko closed this as completed Jun 21, 2017
@abobwhite
Copy link

@rainoko I am still seeing this issue. I am having a problem with getting links on GETs but _links on POST and PUT responses. I want it to always be one or the other.

@gregturn
Copy link
Contributor

Can you please list:

  • Version of Spring Boot
  • Version of Spring HATEOAS
  • Are you using Spring Data REST (sometimes people use SDR, but open their issues here as related project).
  • Any custom configurations you are doing involving message converters, @EnableHypermediaSupport
  • Do you have a Spring MVC controller and some linkTo(methodOn() type code you are using that is yielding awkward stuff?
  • What are the two operations you are performing and where (RestTemplate/curl) that yield different JSON formats?

We need this level of detail to pinpoint what is happening.

@abobwhite
Copy link

Hi @gregturn,

Thanks for the response. I am trying to use use-hal-as-default-json-media-type to make sure I get links consistently and not links for GET requests and _links for POST and PUT requests. I'd be happy if it was either as long as it's consistent.

  • Spring Boot 1.5.7.RELEASE
  • Spring HATEOAS 1.5.7.RELEASE
  • Spring Data REST - yes
  • No @EnableHypermediaSupport but using Gson instead of Jackson so I have this: @EnableAutoConfiguration(exclude = [JacksonAutoConfiguration.class])
  • All my controllers a @RestControllers and I'm using ControllerLinkBuilder.linkTo and manually adding .slash parts, nothing awkward (and working fine for GETs)
  • GET yields links and POST yields _links on the same Resource

@gregturn
Copy link
Contributor

Gson is probably the issue right there. Spring HATEOAS is designed with a vendor neutral format and the actual styling into various forms of hypermedia is done through Jackson annotations and customized Jackson serializers/deserializers/mixins.

This is definitely an area NOT tested with Spring HATEOAS, so I wouldn't expect to work if you disable Jackson and remove its autoconfiguration.

@abobwhite
Copy link

Thanks for the tip. I have completely removed Gson from my app (pom, configuration, etc.) and I still see the same issue.

@abobwhite
Copy link

@gregturn UPDATE: The problem is not related to POST or GET but rather a list of resources vs a single resource. It appears that I am getting links for a list of resources and _links for a single resource. I discovered this after seeing #493

@gregturn
Copy link
Contributor

Show me the method signature. If you are returning a list you're doing it wrong. If you return Resources, that should do the trick.

@abobwhite
Copy link

@gregturn Yes that was the issue! I didn't see that anywhere in an example so had no clue that wouldn't work correctly.

@gregturn
Copy link
Contributor

Well, there are, in fact, unit tests that breach this rule. It's why I've drafted #629, to either log a warning or cause your controller to fail fast if you return a type that you can't expect the HAL (or any future serializer) to handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants