Ragunath
Ragunath

Reputation: 21

How to ignore labels and include only the values POJO to JSON conversion

How to ignore the label "condition" while converting the following POJO to JSON using Jackson?

class Criteria<T> {
    private Map<String, Condition<T>> condition;

    @JsonProperty
    public Map<String, Condition<T>> getCondition() {
        return condition;
    }

    public Criteria<T> setCondition(Map<String, Condition<T>> condition) {
        this.condition = condition;
        return this;
    }

}

class Condition<T> {
    String field;
    T value;

    public String getField() {
        return field;
    }

    public Condition setField(String field) {
        this.field = field;
        return this;
    }

    public T getValue() {
        return value;
    }

    public Condition setValue(T value) {
        this.value = value;
        return this;
    }
}

The actual output is containing the field label "condition" as following.

Actual Output: {"criteria": {"condition": {"EQUALS": {"field": "column1","value": "col_value"}}}}

Expected Output {"criteria": {"EQUALS": {"field": "column1","value": "col_value"}}}

Upvotes: 0

Views: 335

Answers (1)

Ragunath
Ragunath

Reputation: 21

Found the solution, use @JsonValue annotation instead of the @JsonProperty on the respective getter method.

Upvotes: 2

Related Questions