Azure Blob Storage - REST API responses changes from JSON to XML

Test Admin 176 Reputation points
2024-02-07T11:49:02.1+00:00

We are using Azure Blob Storage with Standard tier.

We faced an issue after using the azure blob storage Maven dependency.

We have Java Spring web application with REST API which returns API response in JSON format.

After using the following Maven dependency for azure blob storage in our application pom.xml, all our REST APIs are returning response in XML format.

Unless we set Accept as application/json in the REST API request header.

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.23.0</version>
</dependency>

Question: Why this degrade is happening after using the azure-storage-blob Maven dependency?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,064 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LASNIER, Guillaume 0 Reputation points
    2024-04-04T11:32:23.3933333+00:00

    Hi there,

    We faced a similar issue in one of our project which uses Jackson to marshall/unmarshall HTTP payloads. It did not specify content-negotiation headers so that it assumed that JSON was the default content type. After we added azure-storage-blob, it switched to XML. This is due to the jackson-dataformat-xml dependency that is pulled with azure-storage-blob.

    We tried to exclude jackson-dataformat-xml from the project and build the client with Accept: application/json header option :

    final HttpClientOptions clientOptions = new HttpClientOptions() //
         .setHeaders(
             Arrays.asList(new Header(HttpHeaderName.ACCEPT.getCaseSensitiveName(), "application/json")));
    this.blobServiceClient = new BlobServiceClientBuilder() //
         .connectionString(connectionString) //
         .clientOptions(clientOptions) //
         .buildClient();
    

    Unfortunately this had no effect on the content-type returned by Azure Blob API which was still XML.

    This actually described in the API documentation (c.f. https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs?tabs=microsoft-entra-id#response-headers)

    @KarishmaTiwari-MSFT would it be possible to fix this so that the Accept header is used ?

    Thank you


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.