Reputation: 8955
I have a Java 1.7 starts application. It does have some RESTful api's.
I would like to add @JsonIgnore
to a filed so that it is not returned in the api.
E.g.
import com.fasterxml.jackson.annotation.JsonIgnore;
private java.lang.String username;
@JsonIgnore
private java.lang.String password;
Does not ignore the password.
"member": {
"password": "**************",
"username": "richard"
}
I think the reason why @JsonIgnore
does not work, is because I use com.fasterxml.jackson.annotation.JsonIgnore
. Should I use a different annotation from a different library? i.e. Is my implementation of jaxrs maybe not com.fasterxml.jackson
? How do I tell?
The IntelliJ classpath has:
(I have tried net.minidev.json.annotate.JsonIgnore
with no success)
More info:
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
</dependency>
and
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.11.2</version>
</dependency>
Is this the problem? two versions! I am not sure where the 2.0.5 version comes from, as it is not defined in the pom.
Upvotes: 0
Views: 254
Reputation: 1546
You don't need a @JsonIgnore in this case. You can simply omit the variable that you don't want deserialized(the password in this case) and jackson will just return you the username.
Upvotes: 1