Skip to content

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

@benej60

Description

@benej60

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/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions