Java jsonschema2pojo:如何将注释应用于某些字段
我正在使用jsonschema2pojo,我的一些字段需要特殊的序列化/反序列化。如何在json模式中设置它 以下是我目前的模式:Java jsonschema2pojo:如何将注释应用于某些字段,java,json,jsonschema2pojo,Java,Json,Jsonschema2pojo,我正在使用jsonschema2pojo,我的一些字段需要特殊的序列化/反序列化。如何在json模式中设置它 以下是我目前的模式: "collegeEducation": { "javaJsonView": "com.trp.erd.common.util.Views.InvestmentProfessionalListView", "type": "array", "pos
"collegeEducation": {
"javaJsonView": "com.trp.erd.common.util.Views.InvestmentProfessionalListView",
"type": "array",
"position": 37,
"items": {
"$ref": "#/definitions/CollegeEducation"
}
},
并且需要生成如下所示的属性:
@JsonProperty("collegeEducation")
@JsonView(Views.InvestProfessionalView.class)
@JsonSerialize(using = JsonListSerializer.class)
@JsonDeserialize(using = JsonListDeserializer.class)
@Valid
private List<CollegeEducation> collegeEducation = new ArrayList<CollegeEducation>();
@JsonProperty(“学院教育”)
@JsonView(Views.InvestProfessionalView.class)
@JsonSerialize(使用=JsonListSerializer.class)
@JsonDeserialize(使用=JsonListDeserializer.class)
@有效的
private List collegeEducation=新建ArrayList();
这里是关于jsonschema2pojo中的自定义注释的
使用field::annotate注释字段而不是类
public class SerializationAnnotator extends AbstractAnnotator {
@Override
public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
super.propertyField(field, clazz, propertyName, propertyNode);
if (propertyName.equals("collegeEducation")) {
JAnnotationUse annotation;
annotation = field.annotate(JsonSerialize.class);
annotation.param("using", JsonListSerializer.class);
annotation = field.annotate(JsonDeserialize.class);
annotation.param("using", JsonListDeserializer.class);
}
}
}