Jackson Jaxb Annotation Precedence - @JsonProperty overriding @XmlTransient Jackson Jaxb Annotation Precedence - @JsonProperty overriding @XmlTransient json json

Jackson Jaxb Annotation Precedence - @JsonProperty overriding @XmlTransient


The issue is that the AnnotationIntrospectorPair.hasIgnoreMarker() method basically ignores the @JsonProperty if either introspector detects an ignore marker:

    public boolean hasIgnoreMarker(AnnotatedMember m) {        return _primary.hasIgnoreMarker(m) || _secondary.hasIgnoreMarker(m);    }

ref: github

A workaround is to subclass the JaxbAnnotationIntrospector to get the desired behavior:

public class CustomJaxbAnnotationIntrospector extends JaxbAnnotationIntrospector {    public CustomJaxbAnnotationIntrospector(TypeFactory typeFactory) {        super(typeFactory);    }    @Override    public boolean hasIgnoreMarker(AnnotatedMember m) {        if ( m.hasAnnotation(JsonProperty.class) ) {            return false;        } else {            return super.hasIgnoreMarker(m);        }    }}

Then just use the CustomJaxbAnnotationIntrospector in the AnnotationIntrospectorPair.