I have my @RestController
, that has his parameters mapped in @ModelAttribute
to shorten the list of parameters. However, some of the attributes have to translate to custom objects (i.e. Long -> Instant). My question is there a way to make spring use my setters to set those objects?
Controller mapping
@GetMapping("/v1/my/path")
public Collection<Dto> getAll(@ModelAttribute MyRequest request) {
return someSevice.doSomething(request);
}
ModelAttribute class
public class MyRequest {
private Instant startTime;
private Instant endTime;
private ZoneId timezone;
// How can make spring use this setter to set start time?
private void setStartTimeFromLong(Long startTime) {
this.startTime = Instant.ofEpochSecond(startTime);
}
}