我想用@Valid批注验证我的请求正文,但在Spring Boot中不起作用
我在JAR文件中有一个Request类,无法使用两个字段进行修改。一个字段是对象类型。我的控制器类接受该类对象作为请求主体。当我将下面的JSON传递给控制器时,验证不起作用。下面是代码示例。
要求类别:
public class Request {
Object data;
Map<String, Object> meta;
public <T> T getData() throws ClassCastException {
return (T) this.data;
}
}
Run Code Online (Sandbox Code Playgroud)
另一类:
public class StudentSignUpRequest {
@NotNull(message = "First Name should not be empty")
@Size(max = 64, message = "FirstName should not exceed 64 characters")
private String firstName;
@NotNull(message = "Last Name should not be empty")
@Size(max = 64, message = "LastName should not exceed 64 characters")
private String lastName;
@NotNull(message = "Email cannot …Run Code Online (Sandbox Code Playgroud)