-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Document additional user configuration that's required after setting spring.hateoas.use-hal-as-default-json-media-type
to false
#26814
Comments
Sending HAL-formatted responses when accepting To help us to investigate, can you please provide a complete yet minimal sample that works in one way with Spring Boot 2.5 and in another way when downgraded to Spring Boot 2.4? You can share such a sample with us by zipping it up and attaching it to this issue or pushing it to a separate repository on GitHub. |
This could be a unintended behavior introduced with spring-projects/spring-hateoas#1453 (requested in spring-projects/spring-framework#26212) - the custom A sample application is still very much needed. |
It is okay if this change (sending HAL-formatted responses when accepting I will try to create a sample application. |
Here is the sample application. With Spring Boot 2.4.6 you can make a GET request such as http://localhost:8080/demo/foo with your browser and it will produce an response like this of type With Spring Boot 2.5.0 this will produce |
Thanks for the sample. The problem is that Spring HATEOAS has customised the |
In this particular case I think things would work if |
It is possible to register the default |
Spring HATEOAS doesn't register anything with the default object mapper so I'd expect the response to be in its default form rather than customised to match HAL. To verify this, I added the following bean to your sample:
This results in the links being an array as they were in 2.4.x:
|
That's good news, thanks! I tried to mimic what Spring HATEOAS WebfluxCodecCustomizer would do if @wilkinsona, would your approach be an option for |
It's certainly an option, but I'd prefer not to have to take it. This feels like something that should just work by default but I think we'll need some changes in Spring HATEOAS and/or Spring Framework to get there. Let's see what @odrotbohm and @rstoyanchev make of it and then we can take things from there. |
There are a couple of things playing into this here:
There is a workaround to "solve" your problem: register @Configuration
public class MyMediaTypeConfiguration implements HypermediaMappingInformation {
@Override
public List<MediaType> getMediaTypes() {
return List.of(MediaType.APPLICATION_JSON);
}
} That will register the uncustomized object mapper for use with |
Thank you, @odrotbohm. I think we should turn this into a documentation issue. We can add something to this section of the documentation about Given that setting |
spring.hateoas.use-hal-as-default-json-media-type
to false
If activating the flag registered the configuration above, it would effectively do the same thing as during the 2.4 times. Does it maybe make sense to change the implementation to just do that? |
I'm a little wary of doing that as it'll make it easy to do something that isn't supported, i.e. it's encouraging people to serialise a |
please any update documentation for |
@tmc9031 There hasn't been any changes in this area in Spring Boot 2.7. I see you've also commented on spring-projects/spring-data-rest#2132. Please don't ask what is essentially the same question on multiple issues. If the discussion above isn't enough to help you, I would ask a question on Stack Overflow, taking the time to provide a complete and minimal example of your problem. |
@wilkinsona anything update or Stack Overflow link about Use JSON instead HAL with spring-data-rest ??? thanks a lot |
@tmc9031 The comments above describe your options. You should set the property and then define your own If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. |
Starting with Spring Boot 2.5.0-M3, Spring HATEOAS sends
application/hal+json
responses even though the request containsAccept: application/json
. This change was introduced with commit 5863edf and is considered a breaking change and not documented in the release notes for 2.5. This change results in different rendering of "links" (now as object_links
and before as arraylinks
) and collections (now rendered as object_embedded
and before as arraycontent
).Setting
spring.hateoas.use-hal-as-default-json-media-type
tofalse
will then lead to the following internal server error.The text was updated successfully, but these errors were encountered: