Rahul Reddy
Rahul Reddy

Reputation: 131

JACKSON how to not include the wrapper for a field ?

JACKSON how to not include the wrapper for a field ?

public  class AuthType {
    Map<String,String> properties;

    public Map<String, String> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, String> properties) {
        this.properties = properties;
    }

}

It returns

{"properties":{"authType":"XYZ"}}

but i want to have the

{"authType":"XYZ"}

Any annotation ?

Looks like there is no support for it http://jira.codehaus.org/browse/JACKSON-765 any workaround ?

Upvotes: 3

Views: 445

Answers (3)

Sean Reilly
Sean Reilly

Reputation: 21836

Starting in Jackson 1.9, you can use the @JsonUnwrapped annotation

public  class AuthType {
    Map<String,String> properties;

    @JsonUnwrapped
    public Map<String, String> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, String> properties) {
        this.properties = properties;
    }
}

Upvotes: 1

StaxMan
StaxMan

Reputation: 116620

You can add @JsonAnyGetter to Map; and if you need to read it back, define matching @JsonAnySetter.

Upvotes: 0

noamt
noamt

Reputation: 7835

If your class is actually that simple, use Jackson's custom serializers or simply serialize it as a tree.

Upvotes: 0

Related Questions