I try to validate buy Spring Boot Validation but I can not valid Generics Type. I implementation 'org.springframework.boot:spring-boot-starter-validation' in build.gradle I have a object:
public class BaseAPIRequestDTO<T, U> {
@NotNull
private T content;
@NotNull
private U info;
@NotEmpty
private String signature;}
and Generic Object:
public class ContentRequestDTO {
@NotNull
@NotEmpty(message = "Thiếu transactionId")
private String transactionId;
private DataRequestDTO data;}
..... and controller:
public ResponseEntity<BaseAPIResponseDTO<ContentResponseDTO, InfoResponseDTO>> connnnnn(@RequestBody @Valid BaseAPIRequestDTO< @Valid ContentRequestDTO, @Valid InfoRequestDTO> request, BindingResult bindingResult, HttpServletRequest httpServletRequest)
But I when I clear transactionId on of ContentResponseDTO in request, bindingResult has 0 error result
What do I need to do now? Thank so much.
Did you try to add @Valid in BaseAPIRequestDTO attributes?
Example:
public class BaseAPIRequestDTO<T, U> {
@Valid
@NotNull
private T content;
@Valid
@NotNull
private U info;
@NotEmpty
private String signature;
}
This should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With