I recently had the same issue.
There are several ways to solve it:
- Create file
lombok.config in the root folder of your project with content:
// says that it's primary config (lombok will not scan other folders then)
config.stopBubbling = true
// forces to copy @JsonIgnore annotation on generated constructors / getters / setters
lombok.copyableAnnotations += com.fasterxml.jackson.annotation.JsonIgnore
...
and in your class you can use this annotation as usual, on the field level:
@JsonIgnore
private String name;
Note: if you use lombok @RequiredArgsConstructor or @AllArgsConstructor, then you should remove all usages of @JsonIgnore with @JsonIgnoreProperties (as described in solution #4, or you may still choose solution #2 or #3). This is required because @JsonIgnore annotation is not applicable for constructor arguments.
- Define Getters / Setters manually + add
@JsonIgnore annotation on them:
@JsonIgnore
public String getName() { return name; }
@JsonIgnore
public void setName(String name) { this.name = name; }
- Use
@JsonProperty (it's either read-only or write-only, but no both):
@JsonProperty(access = JsonProperty.Access.READ_ONLY) // will be ignored during serialization
private String name;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) // will be ignored during deserialization
private String name;
- Use
@JsonIgnoreProperties({ "fieldName1", "fieldName2", "..."})
I personally use solution #1 globally and solution #4 for exceptions when class also has annotations @AllArgsConstructor or @RequiredArgsConstructor.