Return 5xx HTTP status for invalid target types with Jackson

InvalidDefinitionException has been introduced in Jackson 2.9 to be
able to differentiate invalid data sent from the client (should still
generate a 4xx HTTP status code) from server side errors like beans with
no default constructor (should generate a 5xx HTTP status code).

Issue: SPR-14925
This commit is contained in:
Sebastien Deleuze
2017-04-05 10:36:01 +02:00
parent 454e61e8ac
commit ed8565894a
5 changed files with 85 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.beans.TypeMismatchException;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
@@ -354,7 +355,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
if (logger.isWarnEnabled()) {
logger.warn("Failed to read HTTP message: " + ex);
}
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
response.sendError(ex.getErrorStatus().orElse(HttpStatus.BAD_REQUEST).value());
return new ModelAndView();
}