FasterXML / jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Apache License 2.0
567 stars 221 forks source link

java.lang.NoSuchMethodError exception #486

Closed anujkgarg closed 3 years ago

anujkgarg commented 3 years ago

I have added below dependencies in pom.xml file -

<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>2.12.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.12.3</version>
            <scope>provided</scope>
        </dependency>

And added below code to read XML data -

       XmlMapper xmlMapper = new XmlMapper();
        // Reads from XML and converts to POJO
        MyClass mycls = xmlMapper.readValue(data, MyClass.class);

        // Reads from POJO and converts to XML
        xmlMapper.writeValue(new File("test.xml"), mycls);

The XmlMapper() is throwing exception -

java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()Lcom/fasterxml/jackson/databind/cfg/MutableCoercionConfig;
    at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:176)
    at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:145)
    at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:127)

As per the issue#471, it can be resolved if all Jackson components have the same version. But still it is not working. Any clue please ?

anujkgarg commented 3 years ago

It works after Invalidate caches/Restart IntelliJ. Hence closing the ticket.