This PR fixes #29588, where we discussed the intended behavior concerning content negotiation with RFC-7807 content types. This is a solution that

  • prefers RFC-7807 content types in case of returning a ProblemDetail (error response)
  • excludes RFC-7807 content types in case of returning all other types (success response)

The test simply allows to add further test cases. Currently, there's no support for ProblemDetail serialized with JAXB (application/problem+xml), but if it is added in the future, the test adds test cases automatically.

Comment From: ueberfuhr

Those are the test cases (=requirements):

Spring Fix RFC-7807 content negotiation

Comment From: ralf-ueberfuhr-ars

I found another issue while fixing the tests: There's one test case throwing an exception and expecting the MVC layer to create a response with an application/problem+json content type and a JSON object, that does not match the requirements of this content type, because it does not conform RFC 7807. (see org.springframework.web.servlet.mvc.method.annotation.ServletAnnotationControllerHandlerMethodTests#produces(boolean))

Is it reasonable to wrap the currently returned body into an RFC-7807-compliant ProblemDetails object instead?

Comment From: rstoyanchev

There is now a fix for #29588, so I'm going to close this. Thanks for the PR in any case.