im使用fasterxml从pojo类创建json模式。如果字段是必填字段,我也会在生成的模式中获取信息,但是我也想检查密码长度是否至少为6位数字。有没有一种注释可以包含字段的min / maxLenght?
Json
{
"username":"Patrick",
"password":""
}
Pojo
...
public class User {
@Id
@GeneratedValue
private int id;
@Column(unique=true)
@NotNull(message = "Username cannot be null")
@JsonProperty(required = true)
private String username;
@NotNull(message = "Name cannot be null")
private String name;
@Size(min = 6, message = "Password is too short")
@NotNull(message = "Password cannot be null")
@JsonProperty(required = true)
private String password;
...
来自pojo的架构:
{
"type" : "object",
"id" : "urn:jsonschema:database:backend:User",
"properties" : {
"id" : {
"type" : "integer"
},
"username" : {
"type" : "string",
"required" : true
},
"name" : {
"type" : "string"
},
"password" : {
"type" : "string",
"required" : true
},
"adress" : {
"type" : "object",
"id" : "urn:jsonschema:database:backend:Address",
"properties" : {
"id" : {
"type" : "integer"
},
"streetNumber" : {
"type" : "string"
},
"street" : {
"type" : "string"
},
"city" : {
"type" : "string"
},
"zip" : {
"type" : "string"
},
"country" : {
"type" : "string"
}
}
}
}
}