-
Notifications
You must be signed in to change notification settings - Fork 472
Provide a mechanism to serve hypermedia responses to requests that accept application/json #1074
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
Comments
On this commit I coded support where a given media type could also register for application/json. It feels kind of clunky. Not sure what a proper API would be that says “when asking for plain JSON, serve HAL”. Maybe it is this? Or perhaps this but just for HAL. |
We have a dedicated HalConfiguration bean to alter rendering of HAL. Perhaps that could be the place to “register” additional media types for the same serializer. |
In fact putting this setting inside HalConfiguration sounds more appealing than encoding such decision into the media type handler itself. It would also grant Boot the ability to inject this through any means desired. |
Thanks for taking a look, Greg. FWIW, 674ea29 doesn't look too clunky to me. One thing I did notice is that I think the default is now that HAL would be served in response to a request that accepts
That's what we really need from a Boot perspective. If you have time to code something up in that direction then I'd be happy to take a look at how it would integrate into Boot. It may allow us to get spring-projects/spring-boot#16020 into Boot 2.2. |
…-FORMS. Inside HalConfiguration and HalFormsConfiguration, add a "wither" to support registering additional mediatypes. This makes it possible for Spring Boot to create a bean that will yield HAL when clients ask for application/json. NOTE: This is NOT implemented in Collection+JSON, UBER, or any other mediatypes, and has not been captured as an interface that all custom mediatypes would pick up. So far, it's custom for HAL and HAL-FORMS. If there is a big draw, we can look at extracting some type of interface. But for now, community feedback would be nice before going down that road.
wdyt @wilkinsona? 10% of this is the code to register extra mediatypes. 90% is the copying of test cases for HAL and HAL-FORMS against both WebFlux and WebMVC. |
I don't think this should be solved on the HMC level but rather in content negotiation with the user explicitly defining which media type she want's to see for a request for Content negotiation for requests is done in MVC. If media type aliasing is supposed to be supported, it should live there. The approach is also at odds with us allowing to register custom media type implementations that would have to know about this, use a dedicated base class so that Boot can tweak their setups as well. All of this has much bigger impact and complexity than MVC aliasing the media type in its content negotiation process. |
Is there any solution/workaround for this issue? I just want to use |
In Spring Boot 1.2 (I think) we added support for serving HAL in response to requests that accept application/json. This was originally mentioned in this comment but I think it ought to be tracked as a separate issue.
The way that we achieve the behaviour described above has changed a bit over time. The current implementation relies on the mutability of
TypeConstrainedMappingJackson2HttpMessageConverter
to addapplication/json
to its supported media types. We need to be able to do something similar for HATEOAS on top of WebFlux and I don't think it's possible without resorting to reflection at the moment.Taking a step back, perhaps it would be better to revisit the approach that we took for MVC at the same time and for Spring HATEOAS to provide a first-class configuration setting for this?
This is a similar issue to #1073 but is about allowing requests for
application/json
to receive a HAL (or other format) response.The text was updated successfully, but these errors were encountered: