HttpMessageNotReadableException
- Typical trigger
- Request body missing, or not parseable as the type the handler expects
Map a Spring MVC 400 to its exception: unreadable JSON body, failed @Valid, missing parameter, type mismatch. Includes ProblemDetail error handling code.
Spring MVC turns a fixed list of exceptions into 400: HttpMessageNotReadableException for an unreadable body, MethodArgumentNotValidException for failed bean validation, MissingServletRequestParameterException, TypeMismatchException and a few others. Find the exception in your logs, then fix the request or handle that exception to return a useful body.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
DefaultHandlerExceptionResolver converts framework exceptions into status codes before your controller returns anything. Its Javadoc lists seven that become 400. The rest of this page assumes you know which one you have, so start by finding its class name in the application log.HttpMessageNotReadableExceptionMethodArgumentNotValidException@Valid or @Validated @RequestBody argument failed validationHandlerMethodValidationExceptionMissingServletRequestParameterException@RequestParam is absentMissingServletRequestPartExceptionServletRequestBindingExceptionTypeMismatchExceptionThree nearby exceptions are not 400. The Javadoc maps MissingPathVariableException to 500, MethodValidationException (service-layer validation) to 500, and HttpMessageNotWritableException to 500. A 500 that looks like a validation problem can mean the constraint sits on a service bean, not a controller method.
Then fire three requests at your own app to see three different causes. These need a running application (replace the port and routes with your own):
# 1. Malformed JSON body -> HttpMessageNotReadableException
curl -s -i -X POST -H 'Content-Type: application/json' -d '{"name": ' http://localhost:8080/api/items
# 2. Text where the handler expects an int -> TypeMismatchException
curl -s -i http://localhost:8080/api/items?page=abc
# 3. Required parameter left out -> MissingServletRequestParameterException
curl -s -i http://localhost:8080/api/search
# Expect: HTTP/1.1 400 on each; the log line names the exception classIf a request returns 400 and the log shows none of the classes in the table, the 400 is coming from somewhere else, such as the embedded server rejecting a malformed request line, or your own code throwing a ResponseStatusException.
curl -s -o /dev/null -w "%{http_code}\n" https://httpbin.org/status/400
# Expect: 400ErrorResponse, which carries the status, headers and an RFC 9457 body. The reference documentation's one-step fix is to extend ResponseEntityExceptionHandler in a @ControllerAdvice:@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
}The status of the response is the status property of the ProblemDetail. To add your own exception with extra fields, return a ProblemDetail from an @ExceptionHandler. This adapts the docs' example to a 400:
@ExceptionHandler(InvalidFilterException.class)
public ProblemDetail handleInvalidFilter(InvalidFilterException ex) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, ex.getMessage());
pd.setProperty("field", ex.getField()); // non-standard field
return pd;
}required = false or a default, so a crawler that drops a parameter still gets a page. For the auth cousins of this error, see 401 in Spring Boot and 403 in Spring Boot.2 questions people ask next, answered from the sources on this page.
Spring MVC maps MethodArgumentNotValidException to 400 in DefaultHandlerExceptionResolver. You can return a different status from your own handler if your API contract prefers it.
Look for the exception class name in the application log. Spring resolves it before the controller runs, and the class name tells you which row of the mapping applied.
Run the free audit, then approve the fixes. Every change can be undone.