Jackson: how to prevent field serialization

weekens picture weekens · Feb 2, 2012 · Viewed 134.2k times · Source

I have an entity class with a password field:

class User {
    private String password;

    //setter, getter..
}

I want this field to be skipped during serialization. But it should still be able to deserialize. This is needed, so that the client can send me a new password, but is not able to read the current one.

How do I accomplish this with Jackson?

Answer

Biju Kunjummen picture Biju Kunjummen · Feb 2, 2012

You can mark it as @JsonIgnore.

With 1.9, you can add @JsonIgnore for getter, @JsonProperty for setter, to make it deserialize but not serialize.