I'm using Spring Boot with header based content negotiation. I have one set of endpoints that are only available to a subset of clients, and the rest are public. My public endpoints are annotated like this:
@PostMapping(consumes = "application/vnd.com.foo+json", produces = "application/vnd.com.foo+json")
and my private ones like this:
@PostMapping(consumes = "application/vnd.com.foo.private+json", produces = "application/vnd.com.foo.private+json")
I want the public endpoints to also consume and produce the private mime types, so that my private clients can just set that mime type on all their requests. Obviously, I can do that by explicitly specifying it on all my public endpoints:
@PostMapping(consumes = {"application/vnd.com.foo+json", "application/vnd.com.foo.private+json"},
produces = {"application/vnd.com.foo+json", "application/vnd.com.foo.private+json"})
but I'd like a neater way to do this.
Is there some way to configure Spring to treat the private mime type as if it 'extends' the public one?
I can configure content negotiation in my WebMvcConfigurer bean:
That seems to work so far, but I'd be interested to see a more standard or elegant way to achieve this.
Edit: This worked for the Accept header, but not Content-Type.