Closed
Description
Affects: 6.0.4
I try to use error handling by setting problemdetails.enabled=true
and internationalising error messages. But I can't achieve my expected result Because in org.springframework.web.bind.MethodArgumentNotValidException::errorsToStringList
field and single quotations were added to messages.
private static List<String> errorsToStringList(
List<? extends ObjectError> errors, Function<ObjectError, String> formatter) {
List<String> result = new ArrayList<>(errors.size());
for (ObjectError error : errors) {
String value = formatter.apply(error);
if (StringUtils.hasText(value)) {
result.add(error instanceof FieldError fieldError ?
fieldError.getField() + ": '" + value + "'" : "'" + value + "'");
}
}
return result;
}
Is there any way to internationalize the field name or remove the field name and brackets from messages?
messages.properties
problemDetail.org.springframework.web.bind.support.WebExchangeBindException= Format is incorrect because {1}
Pattern.phoneNumber= phone number is not correct
Pattern.email= email is not correct
Here is sample output:
{
"type": "about:blank",
"title": "problemDetail.title.org.springframework.web.bind.support.WebExchangeBindException",
"status": 400,
"detail": "Format is incorrect because [phoneNumber: 'phone number is not correct',email: 'email is not correct']",
"instance": "/profile"
}
But I expect:
{
"type": "about:blank",
"title": "problemDetail.title.org.springframework.web.bind.support.WebExchangeBindException",
"status": 400,
"detail": "Format is incorrect because phone number is not correct and email is not correct",
"instance": "/profile"
}