Raise IAE when no converter matches return type
Before this change the AbstractMessageConverterMethodProcessor always raised a 406 if it couldn't find a converter. However if the reason for not finding it is because there is simply no converter for the return value type (i.e. programming error) and doesn't have anything to do with content negotiation, then we should raise a 500 instead and make it easier to figure out what's wrong. Issue: SPR-13135
This commit is contained in:
@@ -32,6 +32,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
@@ -116,6 +117,9 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
|
||||
List<MediaType> requestedMediaTypes = getAcceptableMediaTypes(servletRequest);
|
||||
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(servletRequest, returnValueClass);
|
||||
|
||||
Assert.isTrue(returnValue == null || !producibleMediaTypes.isEmpty(),
|
||||
"No converter found for return value of type: " + returnValueClass);
|
||||
|
||||
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>();
|
||||
for (MediaType requestedType : requestedMediaTypes) {
|
||||
for (MediaType producibleType : producibleMediaTypes) {
|
||||
|
||||
Reference in New Issue
Block a user