Currently, the handleTypeMismatch method in ResponseEntityExceptionHandler does not include information about the required type in its error message.

I’d like to extend this handler so that the response includes the expected type information when a TypeMismatchException occurs. This would make debugging and client error handling easier, as users could immediately see which type was expected.

https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java#L484

e.g.

String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'";
final Class<?> requiredType = e.getRequiredType();
if ( requiredType != null ) {
   String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "' to be a valid " + requiredType.getSimpleName(); 
}

Comment From: rstoyanchev

We don't expose details out of the box that reveal the technology stack (HandlerMethodValidationException is a prime example of that), but we can add the requiredType as an additional message code argument, and that would make it available for inclusion in a customized message as described in the reference.

Comment From: MelleD

Okay, I understand, then the code argument would probably be the right way.