mardi 12 juillet 2016

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) not working

While serialization of the class DataType the dbOptions is been ignored but dataType is being printed with its value.

Note I need to ignore the these property only during serialization and not deserialization.

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "dataType")
@JsonSubTypes(value = {
    @JsonSubTypes.Type(value = DefaultType.class, name = "Default"),
    @JsonSubTypes.Type(value = NumberRangeType.class, name = "NumberRange"),

})
public abstract class DataType {

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
protected String dataType;

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
protected String dbOptions;

public String getDataType() {
    return dataType;
}

public void setDataType(String dataType) {
    this.dataType = dataType;
}

public String getDbOptions() {
    return dbOptions;
}

public void setDbOptions(String dbOptions) {
    this.dbOptions = dbOptions;
}


abstract
public void compute() throws ParseException;

}

Sample output is :

"options":{"dataType":"NumberRange","id":"1","min":0,"max":30}

Don't want dataType to get printed in the output

Aucun commentaire:

Enregistrer un commentaire