I have controller implemented with Spring Boot Rest:
@RestController
@RequestMapping("/example")
public class ExampleController {
@Autowired
private ExampleService exampleService;
@GetMapping("/{id}")
public ExampleResponse getExample(@NotNull @PathVariable("id") String id) {
return exampleService.getExample(id);
}
}
And response DTO:
public class ExampleResponse {
@NotNull
private String id;
@NotNull
private String otherStuff;
// setters and getters
}
Response body is not validated. I have annotated it with @Valid
but null
values still pass. Request validation works well.
How to validate response body?