当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Custom @JsonProperty Annotations

问题描述:

Consider the json schema:

{

"type":"object",

"$schema":"http://json-schema.org/draft-04/schema",

"required":false,

"properties":{

"inventory":{

"type":"object",

"required":false,

"properties":{

"count":{

"type":"number",

"required":false

}

}

}

}

}

When using jsonschema2pojo, this generates a corresponding java object. Extracted from this is the following declaration for count (full class below):

@JsonProperty("count")

private Double count;

package com.test.json;

import java.util.HashMap;

import java.util.Map;

import javax.annotation.Generated;

import com.fasterxml.jackson.annotation.JsonAnyGetter;

import com.fasterxml.jackson.annotation.JsonAnySetter;

import com.fasterxml.jackson.annotation.JsonIgnore;

import com.fasterxml.jackson.annotation.JsonInclude;

import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import org.apache.commons.lang.builder.EqualsBuilder;

import org.apache.commons.lang.builder.HashCodeBuilder;

import org.apache.commons.lang.builder.ToStringBuilder;

@JsonInclude(JsonInclude.Include.NON_NULL)

@Generated("org.jsonschema2pojo")

@JsonPropertyOrder({

"count"

})

public class Inventory{

/**

*

*/

@JsonProperty("count")

private Double count;

@JsonIgnore

private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**

*

* @return

* The count

*/

@JsonProperty("count")

public Double getCount() {

return count;

}

/**

*

* @param count

* The count

*/

@JsonProperty("count")

public void setCount(Double count) {

this.arpu = count;

}

@Override

public String toString() {

return ToStringBuilder.reflectionToString(this);

}

@Override

public int hashCode() {

return HashCodeBuilder.reflectionHashCode(this);

}

@Override

public boolean equals(Object other) {

return EqualsBuilder.reflectionEquals(this, other);

}

@JsonAnyGetter

public Map<String, Object> getAdditionalProperties() {

return this.additionalProperties;

}

@JsonAnySetter

public void setAdditionalProperty(String name, Object value) {

this.additionalProperties.put(name, value);

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: