joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Validation of collection items #904

Open yfcz opened 6 years ago

yfcz commented 6 years ago

Hello,

is it possible to produce POJO with property like: List<@NotNull UUID> list; ?

If not is there some (easy) way how to extend your library to support annotations at collection's items?

Cyc1one commented 4 years ago

Seconding this feature request. We have a raml that defines collections of things and the 'things' require validation, regex and/or maxlength, maximum, etc... (Applies to collections of different types, String, Number, Integer). This should generate code as in the comment form yfcz last August.

goddtriffin commented 1 year ago

Thirding this feature.

Example JSON Schema:

"my_field": {
    "$id": "#/properties/my_type/items/properties/my_field",
    "type": "array",
    "title": "my_field",
    "description": "Enter a string array.",
    "examples": [
        ["value1", "value2"]
    ],
    "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 64,
        "pattern": "^([a-z])[a-z0-9-]*$",
        "$id": "#/properties/my_field/items/properties/my_type/items"
    }
},

Here is the current POJO being generated:

  /**
   * The My_field Schema
   *
   * <p>Enter a string array.
   */
  @JsonProperty("my_field")
  @JsonPropertyDescription("Enter a string array.")
  @Valid
  private List<String> myField;

Where are the minLength, maxLength, pattern constraints?