使从JSON模式生成的POJO类可序列化

Mih*_*nde 2 java serialization json pojo jsonschema2pojo

我使用jsonschema2pojo-maven-plugin v0.4.7从JSON模式生成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"]
            }
Run Code Online (Sandbox Code Playgroud)

得到的POJO类有点如下:

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();
    }

}
Run Code Online (Sandbox Code Playgroud)

我正在使用Spark应用程序中从Schema生成的POJO类之一,该类要求此类实现Serializable以便能够将其用于分布式设置.

我需要生成的类来实现序列化,如下所示:

public class Feature implements Serializable {

}
Run Code Online (Sandbox Code Playgroud)

有没有人知道如何让POJO类实现Serializable?他们的JSON架构设置是否可以序列化?

我一直在谷歌看着没有运气.提前致谢.

Jam*_*rov 9

jsonschema2pojo团队表示已实施:

jsonschema2pojo /问题

"已修复为0.3.7.现在有一个新的扩展属性"javaInterfaces",它接受一个字符串数组,其中每个字符串都是Java接口的完全限定名.生成的类型将实现这些接口."