Java 使从JSON模式生成的POJO类可序列化
我正在使用jsonschema2pojo maven插件v0.4.7从JSON模式生成POJO类。 示例模式如下所示:Java 使从JSON模式生成的POJO类可序列化,java,json,serialization,pojo,jsonschema2pojo,Java,Json,Serialization,Pojo,Jsonschema2pojo,我正在使用jsonschema2pojo maven插件v0.4.7从JSON模式生成POJO类。 示例模式如下所示: "features": { "title": "Feature", "description": "Name and type of every feature in the model", "type": "array", "items": { "
"features": {
"title": "Feature",
"description": "Name and type of every feature in the model",
"type": "array",
"items": {
"properties": {
"columnName": {
"description": "Name of the table column",
"type": "string"
},
"featureName": {
"description": "Name of that column's feature for the pipeline",
"type": "string"
},
"type": {
"description": "Type of the feature",
"type": "string"
}
},
"required": ["columnName", "type"]
}
public class Feature {
/**
* Name of the table column
*
*/
@JsonProperty("columnName")
private String columnName;
/**
* Name of that column's feature for the pipeline
*
*/
@JsonProperty("featureName")
private String featureName;
/**
* Type of the feature
*
*/
@JsonProperty("type")
private String type;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
* Name of the table column
*
* @return
* The columnName
*/
@JsonProperty("columnName")
public String getColumnName() {
return columnName;
}
/**
* Name of the table column
*
* @param columnName
* The columnName
*/
@JsonProperty("columnName")
public void setColumnName(String columnName) {
this.columnName = columnName;
}
/**
* Name of that column's feature for the pipeline
*
* @return
* The featureName
*/
@JsonProperty("featureName")
public String getFeatureName() {
return featureName;
}
/**
* Name of that column's feature for the pipeline
*
* @param featureName
* The featureName
*/
@JsonProperty("featureName")
public void setFeatureName(String featureName) {
this.featureName = featureName;
}
/**
* Type of the feature
*
* @return
* The type
*/
@JsonProperty("type")
public String getType() {
return type;
}
/**
* Type of the feature
*
* @param type
* The type
*/
@JsonProperty("type")
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(columnName).append(featureName).append(type).append(additionalProperties).toHashCode();
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if ((other instanceof Feature) == false) {
return false;
}
Feature rhs = ((Feature) other);
return new EqualsBuilder().append(columnName, rhs.columnName).append(featureName, rhs.featureName).append(type, rhs.type).append(additionalProperties, rhs.additionalProperties).isEquals();
}
}
生成的POJO类大致如下所示:
"features": {
"title": "Feature",
"description": "Name and type of every feature in the model",
"type": "array",
"items": {
"properties": {
"columnName": {
"description": "Name of the table column",
"type": "string"
},
"featureName": {
"description": "Name of that column's feature for the pipeline",
"type": "string"
},
"type": {
"description": "Type of the feature",
"type": "string"
}
},
"required": ["columnName", "type"]
}
public class Feature {
/**
* Name of the table column
*
*/
@JsonProperty("columnName")
private String columnName;
/**
* Name of that column's feature for the pipeline
*
*/
@JsonProperty("featureName")
private String featureName;
/**
* Type of the feature
*
*/
@JsonProperty("type")
private String type;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
* Name of the table column
*
* @return
* The columnName
*/
@JsonProperty("columnName")
public String getColumnName() {
return columnName;
}
/**
* Name of the table column
*
* @param columnName
* The columnName
*/
@JsonProperty("columnName")
public void setColumnName(String columnName) {
this.columnName = columnName;
}
/**
* Name of that column's feature for the pipeline
*
* @return
* The featureName
*/
@JsonProperty("featureName")
public String getFeatureName() {
return featureName;
}
/**
* Name of that column's feature for the pipeline
*
* @param featureName
* The featureName
*/
@JsonProperty("featureName")
public void setFeatureName(String featureName) {
this.featureName = featureName;
}
/**
* Type of the feature
*
* @return
* The type
*/
@JsonProperty("type")
public String getType() {
return type;
}
/**
* Type of the feature
*
* @param type
* The type
*/
@JsonProperty("type")
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(columnName).append(featureName).append(type).append(additionalProperties).toHashCode();
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if ((other instanceof Feature) == false) {
return false;
}
Feature rhs = ((Feature) other);
return new EqualsBuilder().append(columnName, rhs.columnName).append(featureName, rhs.featureName).append(type, rhs.type).append(additionalProperties, rhs.additionalProperties).isEquals();
}
}
有人知道如何使POJO类实现可序列化吗?
它们的JSON模式设置是否使其可序列化
我在谷歌上到处找都找不到运气。
提前感谢。jsonschema2pojo团队表示已经实施:
“针对0.3.7进行了修复。现在有一个新的扩展属性“javaInterfaces”,它接受一个字符串数组,其中每个字符串都是Java接口的完全限定名。生成的类型将实现这些接口。”您可能只是在寻找JSON.stringify?我不认为你有我的问题。我现在编辑了这个问题。谢谢。哈哈,我真的没有。我很抱歉。我的回答是,我仍然在看JavaScript问题,而不是Java问题。我的道歉。:)成功了。非常感谢你。不幸的是,我没有足够的声誉来支持这个答案。