jsonchema2pojo:minLength和maxLength边界如何应用于生成的Java Pojo类?
我想知道,JSON模式中提供的边界是如何转换为JavaPOJO类的 例如,下面是definitions.json文件内容-jsonchema2pojo:minLength和maxLength边界如何应用于生成的Java Pojo类?,java,json,bean-validation,jsonschema2pojo,Java,Json,Bean Validation,Jsonschema2pojo,我想知道,JSON模式中提供的边界是如何转换为JavaPOJO类的 例如,下面是definitions.json文件内容- { "definitions": { "address": { "type": "object", "properties": { "street": { "type": "string", "minLength" : 30, "maxLength" : 100 }, "city":
{
"definitions": {
"address": {
"type": "object",
"properties": {
"street": { "type": "string", "minLength" : 30, "maxLength" : 100 },
"city": { "type": "string", "minLength" : 30, "maxLength" : 100 },
"state": { "type": "string", "minLength" : 30, "maxLength" : 100 }
}
}
}
}
上面的json模式使用jsonschema2pojo实用工具转换为pojo类,如下所示-
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"street",
"city",
"state"
})
public class Address {
@JsonProperty("street")
private String street;
@JsonProperty("city")
private String city;
@JsonProperty("state")
private String state;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* @return
* The street
*/
@JsonProperty("street")
public String getStreet() {
return street;
}
/**
*
* @param street
* The street
*/
@JsonProperty("street")
public void setStreet(String street) {
this.street = street;
}
/**
*
* @return
* The city
*/
@JsonProperty("city")
public String getCity() {
return city;
}
/**
*
* @param city
* The city
*/
@JsonProperty("city")
public void setCity(String city) {
this.city = city;
}
/**
*
* @return
* The state
*/
@JsonProperty("state")
public String getState() {
return state;
}
/**
*
* @param state
* The state
*/
@JsonProperty("state")
public void setState(String state) {
this.state = state;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
@Override
public int hashCode() {
..... Generated implementation
}
@Override
public boolean equals(Object other) {
.....Generated Implementation
}
}
转换为java pojo类时是否忽略该模式?有没有办法将这些模式记录到JavaPOJO类中 minLength/maxLength的值应采用双引号 有关默认值,请参见中提供的示例:
{“type”:“integer”,“default”:“100”}
对于模式案例,请检查Maven插件、CLI和Ant任务的可用性,它们允许通过配置参数激活JSR-303注释
激活后,将生成以下JSR-303注释:
模式规则注释
最大值@小数点最大值
最小值@小数点
最小项,最大项@大小
minLength,maxLength@Size
图案@图案
根据本文档,minLength和maxLength不需要引用。好的,一旦JSR-303被激活,pojo将使用有界注释生成。这个答案解释了如何启用JSR-303。
{
"type": "object",
"properties": {
"name": {
"type": "string",
"pattern": "^[xX]?[0-9a-fA-F]{32}$"
},
"address": { "$ref": "definations.json#/definitions/address" }
}
}