I use Spring 4.1.4and implement a simple service REST. I have a method POSTthat receives an object Personas a request.
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(value = "", method = RequestMethod.POST, headers = "Accept=application/json", consumes = "application/json")
public void add(@Valid @RequestBody Person oPerson) throws Exception {
}
Bean:
public class Person {
public Person(){ }
private String firstname;
private String lastname;
private Integer activeState;
}
My question is: is it possible to set the default value for properties in a bean. Something like that:
@Value(default=7)
private Integer activeState;
I know that when using annotations @RequestParamin a method, @RestControlleryou can set the default value with @RequestParam(value="activeState", required=false, defaultValue="2"), but is it possible to do a similar thing at the class level?
source
share