I am developing a small REST API by using Spring Boot. I am using validation annotations in my entity class:
@NotEmpty(message="Please enter a first name")
private String firstName;
Here is my controller and service:
@RestController
public class CustomerController {
@Autowired
private CustomerService userService;
@PostMapping("/customer")
@ResponseStatus(HttpStatus.CREATED)
public Customer postUser (@RequestBody @Valid Customer customer){
return userService.save(customer);
}
}
public class CustomerService {
@Autowired
private CustomerRepository repository;
@Transactional
public Customer save ( Customer customer){
return repository.save(customer);
}
}
Here is the response I get when I try to send a JSON with an empty firstName Value:
{
"timestamp": "2020-06-08T08:40:08.660+00:00",
"status": 400,
"error": "Bad Request",
"message": "",
"path": "/MVCwebshop/customer"
}
As you can see, the "message" field is empty in the JSON I get. This is also happening when I try to use the default messages. How can I fix this?