FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

@JsonIgnore dont work for collections like set,map,list via Mix-in annotations #25

Closed barelnir closed 10 years ago

barelnir commented 10 years ago

I tried to create an interface that will used as mix-in annotations for jackson.

the annotation @JsonIgnore works for types like String,int,CustomObject but it doesn't work for Collections like Set, List, Map I still get the Collection as part of my JSON output.

I put the @JsonIgnore only on the getter that return the Collection for example:

@JsonIgnore Set getCustomObjects();

I am trying to parse JAXB class so I define the serilizers like this:

objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector()));

objectMapper.addMixInAnnotations(MainObject.class, MainObjectMixInAnnotations.class);

any idea?

cowtowncoder commented 10 years ago

There are no known bugs in @JsonIgnore handling, and I don't see an immediate problem with the code above. But since it is not complete, it is possible something else causes it.

Can you include more complete class definition? Also, which Jackson version are you using?

barelnir commented 10 years ago

The problem was that I had JAXB annotations on the members. it seems that they override the getter mixin annotations. this was wrong because all annotations should be on the getter so i move those annotations

I also change:

@XmlAccessorType(XmlAccessType.FIELD)

to:

@XmlAccessorType(XmlAccessType.PROPERTY)

in the class because FIELD is wrong.

cowtowncoder commented 10 years ago

Ok thanks. Yes; if both field and method have annotations (of same name), method annotations will override ones from fields.