If I pass an unknown value in the Content-Type header (like e.g. This string) the getSupportedMediaTypes() returns falsely an empty list. If I don't pass this header (in case it is needed) the method works fine. Same when I pass a known value like e.g. application/xml. Can you fix that, please?

Comment From: bclozel

Looking at the HttpMediaTypeNotSupportedException, we have two types of constructors for this class:

  • HttpMediaTypeNotSupportedException(MediaType, java.util.List<org.springframework.http.MediaType>) when the given media type is valid but not supported by the handler. We're providing the list of supported media types so that the client can know which types could be used instead
  • HttpMediaTypeNotSupportedException(java.lang.String) when the given media type cannot be parsed (a InvalidMediaTypeException has been thrown) and performing content negotiation doesn't make sense

We could argue that the list of supported media types could be useful still, but at that point the main problem is that the given media type is invalid and so is the request as a result.

Could you expand on why this information is needed in your case? What are you trying to implement, where are you getting this exception?

Comment From: dirweis

I agree that content negotiation won't work with own values but is this not a case for a fallback on the server-side to respond with 415 and let the client know which media types are supported?

Comment From: bclozel

I don't see why we couldn't add that extra information in this case. Knowing more about your use case and how you found out about it would have helped. I'll schedule this as an enhancement.