I’m trying to validate the response of the Spring REST Controller method.
Response is a parameterized type JsonWrapper<MyDto>
@RestController
@RequestMapping
@Validated
public class MyController {
@GetMapping("{myId}")
@Valid
public JsonWrapper<MyDto> get(@PathVariable Long myId) {
MyDto myDto = myService.getById(myId);
return JsonWrapperFactory.ok(myDto);
}
}
@Validated
public class JsonWrapper<T> {
@Valid
private T data;
}
public class MyDto {
@NotNull
private Long id;
@NotEmpty
private String message;
}
However validation of the response doesn’t occur.
How can I validate parameterized type response?