The @JsonIgnore annotation tells Jackson to leave a property out of JSON entirely. The property is not written when an object is serialized, and it is not read when JSON is deserialized into the object. Use it to keep passwords, tokens and internal fields out of API payloads and to break circular references.
It lives in com.fasterxml.jackson.annotation and works the same in plain Jackson and in Spring Boot, which uses Jackson as its default JSON library.
Jackson discovers a logical property from a field, its getter and its setter, and treats them as one unit. When any of those members carries @JsonIgnore, the whole property is ignored in both directions, unless you explicitly re-enable part of it (see the next sections).
| Goal | Tool |
|---|---|
| Hide a property in both directions | @JsonIgnore |
| Hide several properties at class level | @JsonIgnoreProperties({"a", "b"}) |
| Accept input but never output it | @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) |
| Output only, ignore input | @JsonProperty(access = JsonProperty.Access.READ_ONLY) |
Omit null or empty values | @JsonInclude(JsonInclude.Include.NON_NULL) |
| Ignore a type everywhere | @JsonIgnoreType |
Annotate the field, and Jackson skips it in both directions. The example below uses a record-free class so the annotation placement is easy to see.
The password is missing from the output, and the incoming password value is dropped, so the field stays null. Because password is ignored on input, a client cannot set it through this class. If you need clients to send a password but never receive it, use WRITE_ONLY access instead (shown below).
Jackson merges the field, getter and setter of a property. An annotation on any one of them ignores the whole property, so these two forms are equivalent for a standard bean:
Put the annotation on the field for the simplest code. Put it on a getter when the value is computed and has no field, such as a derived getFullName() that you do not want in the output.
The most common real requirement is a request body that includes a password and a response that does not. @JsonIgnore cannot do that on its own, because it blocks both directions. Use @JsonProperty with an access mode.
With WRITE_ONLY, Jackson reads password from incoming JSON and never writes it back. READ_ONLY is the opposite, and suits server-generated values such as createdAt.
Spring Boot configures an ObjectMapper and applies it to every @RestController return value, so the annotation takes effect with no extra setup.
Spring Boot 3 uses jakarta.persistence. Older projects use javax.persistence, and the Jackson annotation is unchanged.
Returning entities directly from controllers couples your API to your database model. For anything beyond a small service, return a DTO or a Java record that contains only the fields you want to publish. That is a stronger guarantee than remembering to annotate each sensitive field.
Two entities that point at each other make Jackson recurse until it throws a StackOverflowError or a JsonMappingException. @JsonIgnore on the back reference fixes it by cutting one direction.
When you still need the link in the output, use @JsonManagedReference on the parent side and @JsonBackReference on the child side, or @JsonIdentityInfo to serialize repeated objects as ids.
@JsonIgnore is not a security boundary on its own. A field added later without the annotation is exposed by default, so prefer DTOs for public APIs.@JsonView.@Transient, which excludes a field from JPA persistence and has no effect on JSON.org.codehaus.jackson.annotate.JsonIgnore. That is the retired Jackson 1 package and Jackson 2 ignores it.@JsonIgnore is placed on a single member. @JsonIgnoreProperties is placed on the class and lists property names, which is handy for hiding inherited or third-party properties. @JsonIgnoreProperties(ignoreUnknown = true) also makes deserialization tolerate extra JSON keys.
Yes, by default. For one direction only, use @JsonProperty(access = ...) with READ_ONLY or WRITE_ONLY.
Yes. Put it on the record component, for example record User(String username, @JsonIgnore String password) {}.
No. It is only read by Jackson, so it does not change what is stored in the database.
@JsonIgnore removes a property from JSON in both directions and works on fields, getters and setters. Use @JsonProperty(access = WRITE_ONLY) when a value should be accepted but never returned, use DTOs to keep entities out of public APIs, and use @JsonIgnore or the reference annotations to break circular object graphs.