Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement of new JacksonFactory to get google credential in Java

I'm trying to authenticate with google-api from a server with the following "old" code:

GoogleTokenResponse tokenResponse =
                new GoogleAuthorizationCodeTokenRequest(TRANSPORT, JSON_FACTORY,
                        CLIENT_ID, CLIENT_SECRET, code, "postmessage").execute();
        // Create a credential representation of the token data.
        GoogleCredential
                credential = new GoogleCredential.Builder()
                .setJsonFactory(JSON_FACTORY)
                .setTransport(TRANSPORT)
                .setClientSecrets(CLIENT_ID, CLIENT_SECRET).build()
                .setFromTokenResponse(tokenResponse);

From old releases of google-api for java, JSON_FACTORY was built doing something like this:

JsonFactory JSON_FACTORY = new JacksonFactory();

But since i've updated to version 1.15.0-rc, JacksonFactory is not found. Looks like it has been refactored or removed, but i can't find any example to replace this line of code.

What should i use? Implementation of JsonFactory for sure, but some standard implementation may already exist?

like image 896
kij Avatar asked May 22 '13 14:05

kij


1 Answers

Finally found the JacksonFactory class. It has been separated and is available in the following dependency:

    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-jackson2</artifactId>
        <version>1.15.0-rc</version>
    </dependency>

So the Java code doesn't change.

like image 115
kij Avatar answered Nov 10 '22 19:11

kij