Java-使用更多设置(minLenght)从pojos生成json模式

时间:2019-03-21 17:59:44

标签: java json

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"
        }
      }
    }
  }
}

0 个答案:

没有答案