'Hibernate validator error response is too short to handle
I use hibernate @NotNull validator .Error response body is too small but it must be large. I get hibernate validator error response like this:
{
"timestamp": "2022-02-17T18:05:11.305+00:00",
"status": 400,
"error": "Bad Request",
"path": "/project"
}
but I should error response like this: How can be this achieved?
{
"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" }
Code is like that:
@PostMapping
public ResponseEntity<ProjectDto> createProject(@Valid @RequestBody ProjectDto project){
return ResponseEntity.ok(projectServiceImpl.save(project));
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProjectDto {
private Long id;
@NotNull(message="project name cannot be null")
private String projectName;
@NotNull
private String projectCode;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
