从json架构

时间:2017-09-14 12:55:50

标签: json jsonschema

我必须创建一个json模式,这样当我从中创建类时,字段名称与json键不同。 我想将json密钥映射到使用此模式创建的域对象中的自定义字段

考虑json方案

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "sample_master",
  "title": "Person",
  "type": "object",
  "name":"SampleMasterFile",
  "properties": {
    "first_Name": {
      "type": "string"

    },
    "SYM_CD": {
      "type": "string"
     // "name":"symCdValue" -> some trick here so that when the domain is created, the field name corresponding to SYM_CD is symCdValue
    },
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["first_Name", "SYM_CD","age"],
  "additionalProperties" : false
}

这是上面架构中生成的类。我希望为json键SYM_CD生成的字段映射到symCdValue

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonPropertyOrder({
    "first_Name",
    "SYM_CD",
    "age"
})
public class SampleMaster {


    @JsonProperty("first_Name")
    private String firstName;

    @JsonProperty("SYM_CD")
    private String sYMCD; // I want this field to be named as symCdValue ?

    @JsonProperty("age")
    @JsonPropertyDescription("Age in years")
    private Integer age;

    @JsonProperty("first_Name")
    public String getFirstName() {
        return firstName;
    }

    @JsonProperty("first_Name")
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @JsonProperty("SYM_CD")
    public String getSYMCD() {
        return sYMCD;
    }

    @JsonProperty("SYM_CD")
    public void setSYMCD(String sYMCD) {
        this.sYMCD = sYMCD;
    }

    @JsonProperty("age")
    public Integer getAge() {
        return age;
    }

    @JsonProperty("age")
    public void setAge(Integer age) {
        this.age = age;
    }

// Removed to string, equals method

}

0 个答案:

没有答案