Spring @JsonIgnore not working

If you are using an implementation of Jackson and its annotations are not working it's probably because you have another dependency of jackson with better precedence. Hence if you want to assure that certain implementation of jackson prevales (IMHO the best choice is the one that you have all classes already annotated with, because probably it came with other dependencies) specify this dependency in the pom of the application module. So if you have in multiple modules all your entities annotated with

import com.fasterxml.jackson.annotate.JsonIgnore;  // note: com. instead of org.

Instead of replacing all imports just specify the corresponding dependency in the application pom:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>

This will clarify to Spring Boot that this is the implementation you want to use.


I have finally found a solution. I changed the import statement from

import com.fasterxml.jackson.annotate.JsonIgnore;  // com. instead of org.

to

import org.codehaus.jackson.annotate.JsonIgnore;

Basically you have to make sure you are using the same class everywhere.


The annotation should only be on the 'get' methods. You seem to have @Json... annotations on your private fields.


Putting @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) before the field declaration solved the problem for me.

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private List<Survey> surveys =  new ArrayList<>();

I'm using jackson version 2.11.3