Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jsonschema2pojo:如何将注释应用于某些字段_Java_Json_Jsonschema2pojo - Fatal编程技术网

Java jsonschema2pojo:如何将注释应用于某些字段

Java jsonschema2pojo:如何将注释应用于某些字段,java,json,jsonschema2pojo,Java,Json,Jsonschema2pojo,我正在使用jsonschema2pojo,我的一些字段需要特殊的序列化/反序列化。如何在json模式中设置它 以下是我目前的模式: "collegeEducation": { "javaJsonView": "com.trp.erd.common.util.Views.InvestmentProfessionalListView", "type": "array", "pos

我正在使用jsonschema2pojo,我的一些字段需要特殊的序列化/反序列化。如何在json模式中设置它

以下是我目前的模式:

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