spring-projects / spring-projects/spring-framework
Allow the actual value to be rendered to filter producible media types in content negotiation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
Currently, content negotiation is completely type-based and doesn't consider the actual value to be rendered.
My use case is as follows: Spring HATEOAS users usually work with RepresentationModel instances they return from controllers. Spring Data REST currently does so as well, and it has two different HttpMessageConverters registered, one for HAL and one for HAL FORMS. Whether the latter can reasonably be rendered depends on the state of the RepresentationModel and there is currently no way to filter the list of producible media types based on the value.
I've looked into ResponseBodyAdvice as it has access to all the moving parts I need, but I cannot throw a HttpMediaTypeNotAcceptableException from that one as the exception is a checked one. I need to be able to produce a 406 in case someone asks for HAL FORMS only but depending on the value to be rendered it cannot be produced properly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Spring MVC content negotiation around HttpMessageConverters and ResponseBodyAdvice, including the checked HttpMediaTypeNotAcceptableException mentioned here. No file or test is named; done should include a way to consider the actual value, reject an unrenderable requested media type with 406, and preserve valid negotiation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100