Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JsonProperty and equivalents should merge with AnnotationIntrospectorPair #4364

Closed
cowtowncoder opened this issue Feb 3, 2024 · 4 comments
Labels
2.17 Issues planned at earliest for 2.17
Milestone

Comments

@cowtowncoder
Copy link
Member

Describe your Issue

If a property has multiple naming annotations -- such as standard @JsonProperty, and @JacksonXmlProperty from jackson-dataformat-xml -- and there are 2 AnnotationIntrospectors, then AnnotationIntrospectorPair should merge parts so that if the Primary introspector has no value (empty String or null), value from secondary should be used, for:

  1. Local name
  2. Namespace

so that, for example:

@JacksonXmlProperty(isAttribute=true)
@JsonProperty(namespace="uri:ns1", value="prop")
public int value;

where first annotation has precedence (annotation introspector that handles it is the first introspector configured for AnnotationIntrospectorPair) we should have localName and namespace from @JsonProperty since JacksonXmlProperty defines neither (that is, has defaults of "").
Currently this is not the case.

@SimonCockx
Copy link

SimonCockx commented Jun 21, 2024

This changed existing behaviour, which is currently causing us trouble. Any advice on how to migrate?

We have a custom XML annotation introspector which explicitly sets the wrapper name to Property.NO_NAME if our custom annotation is present and the type is a list:

    @Override
    public PropertyName findWrapperName(Annotated ann) {
        if (ann.hasAnnotation(RosettaAttribute.class) && hasCollectionType(ann)) {
            // Disable wrapping of lists.
            return PropertyName.NO_NAME;
        }
        return super.findWrapperName(ann);
    }

This used to work in Jackson 2.15.

Unfortunately, due to this change, PropertyName.NO_NAME is now merged with PropertyName.DEFAULT from the default Jackson XML annotation introspector, and the new behaviour prefers PropertyName.DEFAULT over PropertyName.NO_NAME. The previous behaviour would prefer PropertyName.NO_NAME.

I have not found a way to fix this. Is there a way to get rid of the default annotation processor? Should I raise an issue?

@cowtowncoder
Copy link
Member Author

cowtowncoder commented Jun 22, 2024

@SimonCockx you should file an issue for jackson-dataformat-xml, referencing this issue. And including version you are using (2.17.1 perhaps).

One way you could avoid this would be to sub-class AnnotationIntrospectorPair, combine introspector explicitly (I assume you need 2 AnnotationIntrospectors?). Or use/create single AnnotationIntrospector.
But logic of combining may hard to override.

@cowtowncoder cowtowncoder added 2.17 Issues planned at earliest for 2.17 and removed to-evaluate Issue that has been received but not yet evaluated labels Jun 22, 2024
@cowtowncoder cowtowncoder added this to the 2.17.0 milestone Jun 22, 2024
@SimonCockx
Copy link

@cowtowncoder Thanks for the response. Actually I only need one, but I have not found a way to disable the default annotation processor, which seems to be somewhat "hardcoded" in the basicConfig when constructing an ObjectMapper. But let's maybe continue this thread in the new issue.

@cowtowncoder
Copy link
Member Author

NOTE: #4595 changes behavior for 2.17.2 to not merge NO_NAME case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.17 Issues planned at earliest for 2.17
Projects
None yet
Development

No branches or pull requests

2 participants