Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson @JsonIgnore changed semantics?

Tags:

java

json

jackson

We just upgraded some maven dependencies, that triggered an update of Jackson from 1.7.x to 1.9.x

We use to annotate @JsonIgnore on setter methods, on methods not supposed to be set from client side. for example: the owner of an object (with should be set from the authentication principal), etc.

It seems to us that the semanthincs of this annotation have changed, is that possible? now the field is been jsonignored in all case, and not only when being set.

is that the case? is there an alternative way in 1.9 to implement ignore SET only?

thanks! r.

like image 308
Rafael Avatar asked Feb 15 '12 19:02

Rafael


1 Answers

Ok, I think I found and explicit mention to this issue in the javadoc. (jackson documentation is not easy to go through).

In addition, starting with Jackson 1.9, if this is the only annotation associated with a property, it will also cause cause the whole property to be ignored: that is, if setter has this annotation and getter has no annotations, getter is also effectively ignored. It is still possible for different accessors to use different annotations; so if only "getter" is to be ignored, other accessors (setter or field) would need explicit annotation to prevent ignoral (usually JsonProperty).

like image 64
Rafael Avatar answered Oct 17 '22 05:10

Rafael