简体   繁体   English

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

[英]Make POJO class generated from JSON schema serializable

I am using the jsonschema2pojo-maven-plugin v0.4.7 to generate POJO classes from a JSON schema. 我正在使用jsonschema2pojo-maven-plugin v0.4.7从JSON模式生成POJO类。 A sample schema is as follows: 示例架构如下:

 "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"]
            }

The resulting POJO class is somewhat as follows: 生成的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();
    }

}

I am using one of the POJO classes generated from the Schema in a Spark Application which requires that this class implements Serializable to be able to use it a distributed setting. 我在Spark应用程序中使用从架构生成的POJO类之一,该类要求该类实现Serializable才能使用它的分布式设置。

I need the resulting class to implement Serialization like follows: 我需要生成的类来实现序列化,如下所示:

public class Feature implements Serializable {

}

Does anyone know a way to make a POJO class implement Serializable? 有谁知道一种使POJO类实现Serializable的方法? Is their a JSON schema setting to make it serializable? 是他们的JSON模式设置以使其可序列化吗?

I have looked all over google with no luck. 我在整个Google上都没有运气。 Thanks in advance. 提前致谢。

jsonschema2pojo team says it has been implemented: jsonschema2pojo小组表示已实施:

jsonschema2pojo/issues jsonschema2pojo /问题

"Fixed for 0.3.7. There is now a new extension property "javaInterfaces" that takes an array of strings, where each string is the fully qualified name of a Java interface. The generated type will implement those interfaces." “已修复为0.3.7。现在有了一个新的扩展属性“ javaInterfaces”,该属性采用字符串数组,其中每个字符串都是Java接口的完全限定名称。生成的类型将实现这些接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM