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

NoSuchMethod error using BOM #475

Closed ghost closed 3 years ago

ghost commented 3 years ago
    private void uploadToBlobStorage(byte[] contentBytes, String filename) {
        String accountName = System.getenv("AZURE_STORAGE_ACCOUNT_NAME");
        String accountKey = System.getenv("AZURE_STORAGE_ACCOUNT_KEY");
        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
        String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);

        BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
        BlobContainerClient containerClient = storageClient.getBlobContainerClient(System.getenv("AZURE_ATTACHMENTS_CONTAINER"));

        BlobClient blobClient = containerClient.getBlobClient(filename);
        blobClient.upload(new ByteArrayInputStream(contentBytes), contentBytes.length);
    }

The above code does not work. I am getting a java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()Lcom/fasterxml/jackson/databind/cfg/MutableCoercionConfig error.

My dependency tree looks ok:

[INFO] +- com.azure:azure-storage-blob:jar:12.10.0:compile
[INFO] |  +- com.azure:azure-core:jar:1.12.0:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.11.3:compile
[INFO] |  |  |  +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.11.3:compile
[INFO] |  |  |  |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] |  |  |  |  \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] |  |  |  +- org.codehaus.woodstox:stax2-api:jar:4.2.1:compile
[INFO] |  |  |  \- com.fasterxml.woodstox:woodstox-core:jar:6.2.1:compile
[INFO] |  |  +- io.projectreactor:reactor-core:jar:3.3.12.RELEASE:compile
[INFO] |  |  |  \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] |  |  \- io.netty:netty-tcnative-boringssl-static:jar:2.0.35.Final:compile
[INFO] |  +- com.azure:azure-storage-common:jar:12.10.0:compile
[INFO] |  |  \- com.azure:azure-core-http-netty:jar:1.7.1:compile
[INFO] |  |     +- io.netty:netty-handler:jar:4.1.54.Final:compile
[INFO] |  |     |  +- io.netty:netty-common:jar:4.1.54.Final:compile
[INFO] |  |     |  +- io.netty:netty-resolver:jar:4.1.54.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport:jar:4.1.54.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec:jar:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-handler-proxy:jar:4.1.54.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec-socks:jar:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-buffer:jar:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-codec-http2:jar:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-transport-native-unix-common:jar:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.54.Final:compile
[INFO] |  |     +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.54.Final:compile
[INFO] |  |     \- io.projectreactor.netty:reactor-netty:jar:0.9.15.RELEASE:compile
[INFO] |  \- com.azure:azure-storage-internal-avro:jar:12.0.2:compile
[INFO] \- org.apache.commons:commons-email:jar:1.5:compile
[INFO]    \- com.sun.mail:javax.mail:jar:1.5.6:compile
[INFO]       \- javax.activation:activation:jar:1.1:compile
[INFO] ------------------------------------------------------------------------

In my pom.xml, I have something like this:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.azure</groupId>
                <artifactId>azure-sdk-bom</artifactId>
                <version>1.0.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-storage-blob</artifactId>
        </dependency>
    </dependencies>
cowtowncoder commented 3 years ago

You do not seem to have a dependency to jackson-databind (or jackson-core) so I can't say for sure, but the error definitely looks like you had an old version of jackson-databind. Maybe Azure SDK bom does not include compliant version settings for Jackson components (there is jackson-bom that does).

ghost commented 3 years ago

I solved this one by using mvn clean package instead of mvn package in our ci/cd script. I am closing this issue.