使从 JSON 模式生成的 POJO class 可序列化
Make POJO class generated from JSON schema serializable
我正在使用 jsonschema2pojo-maven-plugin v0.4.7 从 JSON 模式生成 POJO classes。
示例架构如下:
"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"]
}
生成的 POJO class 大致如下:
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();
}
}
我正在使用从 Spark 应用程序中的架构生成的 POJO classes 之一,它要求此 class 实现 Serializable 以便能够将其用作分布式设置。
我需要结果 class 来实现序列化,如下所示:
public class Feature implements Serializable {
}
有谁知道使 POJO class 实现可序列化的方法吗?
他们的 JSON 架构设置是否使其可序列化?
我找遍了 google,但运气不佳。
提前致谢。
jsonschema2pojo 团队表示已实施:
"Fixed for 0.3.7. There is now a new extension property "javaInterfaces" 接受一个字符串数组,其中每个字符串都是 Java 接口的完全限定名称。生成的类型将实现这些接口。"
我正在使用 jsonschema2pojo-maven-plugin v0.4.7 从 JSON 模式生成 POJO classes。 示例架构如下:
"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"]
}
生成的 POJO class 大致如下:
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();
}
}
我正在使用从 Spark 应用程序中的架构生成的 POJO classes 之一,它要求此 class 实现 Serializable 以便能够将其用作分布式设置。
我需要结果 class 来实现序列化,如下所示:
public class Feature implements Serializable {
}
有谁知道使 POJO class 实现可序列化的方法吗? 他们的 JSON 架构设置是否使其可序列化?
我找遍了 google,但运气不佳。 提前致谢。
jsonschema2pojo 团队表示已实施:
"Fixed for 0.3.7. There is now a new extension property "javaInterfaces" 接受一个字符串数组,其中每个字符串都是 Java 接口的完全限定名称。生成的类型将实现这些接口。"