I am using the javax.validation.constraints.NotEmpty library to validate POJO class for rest request. Within class i have used below annotaion.
@ApiModelProperty(value = "Name", required = true)
@NotEmpty(message = "Name is required")
private String name;
Above code is working fine and returning the response as below when name is empty
"code": "NotEmpty",
"message": "Name is required"
Is there any way through which i can display/provide the my own Custom code value instead of "code": "NotEmpty". Something like "code": "INVALID NAME".
Any approach suggestion on this must be appreciated.
The best way is to implement your own exception handler and build the entire response as you need to it, as simple text, JSON, XML, etc..
There is also the Payload option:
Which should get you this: