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

@JacksonXmlRootElement malfunction when using it with multiple XmlMappers and disabling annotations #282

Closed
benej60 opened this issue Feb 16, 2018 · 2 comments
Milestone

Comments

@benej60
Copy link

benej60 commented Feb 16, 2018

Found this in version 2.9.4 running some tests that go back and forth serializing with an XML mapper that uses annotations, and another one that ignores them. May be related to issue #171 and the cache of class annotations.

When running this code, the second print statement should use the annotation's localName but it instead uses the class name.

@JacksonXmlRootElement(localName = "myname")
public class XMLTest {

    public static void main(String[] s) throws Exception {

        final ObjectMapper xmlMapper = new XmlMapper();
        final ObjectMapper noAnnotationsXmlMapper = xmlMapper.copy()
                .configure(MapperFeature.USE_ANNOTATIONS, false)
                .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

        System.out.println(noAnnotationsXmlMapper.writeValueAsString(new XMLTest()));
        System.out.println(xmlMapper.writeValueAsString(new XMLTest()));

    }

}

Output:

<XMLTest/>
<XMLTest/>
@cowtowncoder
Copy link
Member

Ok, does sound like caching of root names might be causing the issue here.

cowtowncoder added a commit that referenced this issue May 21, 2018
@cowtowncoder cowtowncoder changed the title @JacksonXmlRootElement malfunction when using it with multiple XmlMappers and disabling annotations @JacksonXmlRootElement malfunction when using it with multiple XmlMappers and disabling annotations May 21, 2018
@cowtowncoder cowtowncoder added this to the 2.9.6 milestone May 21, 2018
@cowtowncoder
Copy link
Member

Turned out to be inadvertent sharing of root name lookup cache. Was resolved for 3.0 (due to the way construction changed), but test now covers 2.9 and 3.0. Fix will be in 2.9.6.

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

No branches or pull requests

2 participants