Azure + SpringBoot ‘com/fasterxml/jackson/core/JsonFactory’

Solution for Azure + SpringBoot ‘com/fasterxml/jackson/core/JsonFactory’
is Given Below:

I’m getting started with Java + SprintBoot + AzureStorage. I just created a project thru Spring initializer using the following configuration:

spring project config

I’m trying to create a simple rest method to return the list of shares from Azure, but i’m getting the following error:

Exception Details:
  Location:
    com/fasterxml/jackson/databind/cfg/MapperBuilder.streamFactory()Lcom/fasterxml/jackson/core/TokenStreamFactory; @7: areturn
  Reason:
    Type 'com/fasterxml/jackson/core/JsonFactory' (current frame, stack[0]) is not assignable to 'com/fasterxml/jackson/core/TokenStreamFactory' (from method signature)
  Current Frame:
    bci: @7
    flags: { }
    locals: { 'com/fasterxml/jackson/databind/cfg/MapperBuilder' }
    stack: { 'com/fasterxml/jackson/core/JsonFactory' }

Nothing special in my code to get shares as far as i can see:

AzureStoreService

@Service
public class AzureStorageService {

    @Value("${azure.storage.accountName}")
    private String accountName;

    @Value("${azure.storage.accountKey}")
    private String token;

    private ShareServiceClient createServiceClient() {
        String shareURL = String.format("https://%s.file.core.windows.net", accountName);
        return new ShareServiceClientBuilder().endpoint(shareURL).sasToken(token).buildClient();
    }

    public List<String> listShares() {
        List<String> shares = new ArrayList<>(0);
        ShareServiceClient client = createServiceClient();
        client.listShares().forEach(item -> shares.add(item.getName()));
        return shares;
    }
}

AzureController

@RestController
@RequestMapping("/storage")
public class AzureController {

    @Autowired
    private AzureStorageService azureStorageService;

    @GetMapping("/list-shares")
    private ResponseEntity<List<String>> listShares() {
        List<String> shares = azureStorageService.listShares();
        return new ResponseEntity<>(shares, HttpStatus.OK);
    }
}

I guess the problem is related to library version conflicts between Spring Boot and Azure, but which one should I keep and how.

You probably faced this issue before, any hint / suggestion is welcome.

Thanks a lot in advance!

If you are using springboot then jackson is added by default,

So the version of jackson you are adding manually is probably conflicting with the one which the spring boot adds,

Try to delete the jackson dependencies from your pom.xml.

If you need to override the version which was added by default by the spring boot, then you need to exclude it first and then add your own dependency.

<dependency> 
        <groupId>com.fasterxml.jackson.core</groupId> 
        <artifactId>jackson-core</artifactId> 
        <version>2.12.1</version> 
 </dependency> 

I finally found the root cause for this problem:

One important thing that I forgot to mention is that I’m using JBoss to deploy the application, and is here the the problem comes from, becasue of the modules that JBoss includes. So I just needed to add a deployment estructure file.

jboss-deployment-estructure.xml:

<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <module-alias name="deployment.AzureTestWS"/>
        <exclusions>
            <module name="com.fasterxml.jackson.core.jackson-core"/>
            <module name="com.fasterxml.jackson.core.jackson-databind"/>
            <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider"/>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
            <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310"/>
            <module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

this worked for mi on JBoss EAP 7.2