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);
}
}
If the JSON interface changes, and count becomes countOfItems, both the JSON property annotation, AND the java variable name change, which affects getters and setters:
@JsonProperty("countOfItems")
private Double countOfItems;
@JsonProperty("countOfItems")
public Double getCountOfItems()
@JsonProperty("countOfItems")
public void setCountOfItems(Double countOfItems)
I would like to be able to customise the generated class so that implementing java code didn't have to change, i.e.:
@JsonProperty("countOfItems")
private Double count;
@JsonProperty("countOfItems")
public Double getCount()
@JsonProperty("countOfItems")
public void setCount(Double count)
Is this kind of feature supported using JSON schema and jsonschema2pojo? I can't find any information on how to do this on the json schema or jsonscema2pojo documentation.
Obviously this could be achieved by hand crafting the java object, but I'd rather keep using generated classes.