With Jackson, it\'s easy to disable all annotations for a given ObjectMapper
.
Is there a way to only disable one given annotation?
// disable al
I think it's a better idea to override findPropertiesToIgnore
method like this:
JacksonAnnotationIntrospector ignoreJsonTypeInfoIntrospector = new JacksonAnnotationIntrospector() {
@Override
public String[] findPropertiesToIgnore(AnnotatedClass ac) {
ArrayList ret = new ArrayList();
for (Method m : ac.getRawType().getMethods()) {
if(ReflectionUtils.isGetter(m)){
if(m.getAnnotation(Transient.class) != null)
ret.add(ReflectionUtils.getPropertyName(m));
}
};
return ret.toArray(new String[]{});
}
};
objectMapper = new ObjectMapper();
objectMapper.setAnnotationIntrospector(ignoreJsonTypeInfoIntrospector);