Is it possible to override the default response POJO of Spring Hibernate validator?
Currently when a validation gets failed then a very big response returned to the client as shown below. But I don't want the client to provide the full error response of hibernate validator and instead to send some key-value pair regarding the error message.
{
"timestamp": "2018-05-28T18:12:56.705+0000",
"status": 400,
"error": "Bad Request",
"errors": [
{
"codes": [
"NotBlank.abc.xyz",
"NotBlank.xyz",
"NotBlank.java.lang.String",
"NotBlank"
],
"arguments": [
{
"codes": [
"abc.xyz",
"xyz"
],
"arguments": null,
"defaultMessage": "transactionId",
"code": "transactionId"
}
],
"defaultMessage": "xyz is mandatory parameter , please provide appropriate value",
"objectName": "abc",
"field": "xyz",
"rejectedValue": "",
"bindingFailure": false,
"code": "NotBlank"
}
],
"message": "Validation failed for object='xyz'. Error count: 1",
"path": "/path/create/1"
}
MethodArgumentNotValidException
and notBindException
– Frenetic