Add required type to TypeMismatchException message args
Closes gh-35837
This commit is contained in:
parent
f4ee120a42
commit
4847ee80b0
|
|
@ -175,7 +175,7 @@ Message codes and arguments for each error are also resolved via `MessageSource`
|
|||
|
||||
| `TypeMismatchException`
|
||||
| (default)
|
||||
| `+{0}+` property name, `+{1}+` property value
|
||||
| `+{0}+` property name, `+{1}+` property value, `+{2}+` simple name of required type
|
||||
|
||||
| `UnsatisfiedServletRequestParameterException`
|
||||
| (default)
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
|
|||
|
||||
/**
|
||||
* Customize the handling of {@link TypeMismatchException}.
|
||||
* <p>By default this method creates a {@link ProblemDetail} with the status
|
||||
* <p>By default, this method creates a {@link ProblemDetail} with the status
|
||||
* and a short detail message, and also looks up an override for the detail
|
||||
* via {@link MessageSource}, before delegating to
|
||||
* {@link #handleExceptionInternal}.
|
||||
|
|
@ -480,7 +480,8 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
|
|||
protected @Nullable ResponseEntity<Object> handleTypeMismatch(
|
||||
TypeMismatchException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
|
||||
|
||||
Object[] args = {ex.getPropertyName(), ex.getValue()};
|
||||
Object[] args = {ex.getPropertyName(), ex.getValue(),
|
||||
(ex.getRequiredType() != null ? ex.getRequiredType().getSimpleName() : "")};
|
||||
String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'";
|
||||
String messageCode = ErrorResponse.getDefaultDetailMessageCode(TypeMismatchException.class, null);
|
||||
ProblemDetail body = createProblemDetail(ex, status, defaultDetail, messageCode, args, request);
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ class ResponseEntityExceptionHandlerTests {
|
|||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage(
|
||||
ErrorResponse.getDefaultDetailMessageCode(TypeMismatchException.class, null), locale,
|
||||
"Failed to set {0} to value: {1}");
|
||||
"Failed to set {0} to value: {1} for type {2}");
|
||||
|
||||
this.exceptionHandler.setMessageSource(messageSource);
|
||||
|
||||
|
|
@ -253,7 +253,7 @@ class ResponseEntityExceptionHandlerTests {
|
|||
new TypeMismatchException(new PropertyChangeEvent(this, "name", "John", "James"), String.class));
|
||||
|
||||
ProblemDetail body = (ProblemDetail) entity.getBody();
|
||||
assertThat(body.getDetail()).isEqualTo("Failed to set name to value: James");
|
||||
assertThat(body.getDetail()).isEqualTo("Failed to set name to value: James for type String");
|
||||
}
|
||||
finally {
|
||||
LocaleContextHolder.resetLocaleContext();
|
||||
|
|
|
|||
Loading…
Reference in New Issue