Skip to content
Permalink
Browse files
fix: use Gson instead of Jackson (#1661)
* use GSon instead of Jackson

* remove jackson2

* fix callback
  • Loading branch information
elharo committed Jan 14, 2021
1 parent 8dc6c92 commit 63ed2caecc200a407ef40b249bed158f18e2c5ae
Showing with 57 additions and 64 deletions.
  1. +4 −4 .../com/google/api/client/googleapis/extensions/appengine/auth/oauth2/AppIdentityCredentialTest.java
  2. +4 −4 ...ava/com/google/api/client/googleapis/notifications/json/jackson2/JacksonNotificationCallback.java
  3. +0 −5 google-api-client/pom.xml
  4. +1 −1 ...c/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeTokenRequest.java
  5. +1 −1 ...-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleRefreshTokenRequest.java
  6. +1 −1 google-api-client/src/main/java/com/google/api/client/googleapis/json/package-info.java
  7. +1 −1 ...lient/src/main/java/com/google/api/client/googleapis/notifications/TypedNotificationCallback.java
  8. +1 −1 ...t/src/main/java/com/google/api/client/googleapis/notifications/json/JsonNotificationCallback.java
  9. +2 −2 ...ient/src/main/java/com/google/api/client/googleapis/testing/auth/oauth2/MockGoogleCredential.java
  10. +2 −2 .../src/main/java/com/google/api/client/googleapis/testing/auth/oauth2/MockTokenServerTransport.java
  11. +2 −2 ...t/src/main/java/com/google/api/client/googleapis/testing/compute/MockMetadataServerTransport.java
  12. +2 −2 google-api-client/src/main/java/com/google/api/client/googleapis/util/Utils.java
  13. +2 −2 ...ent/src/test/java/com/google/api/client/googleapis/auth/oauth2/DefaultCredentialProviderTest.java
  14. +2 −2 ...t/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeFlowTest.java
  15. +2 −2 ...st/java/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeTokenRequestTest.java
  16. +2 −2 ...e-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleCredentialTest.java
  17. +4 −4 ...-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleIdTokenVerifierTest.java
  18. +5 −5 ...lient/src/test/java/com/google/api/client/googleapis/auth/oauth2/GooglePublicKeysManagerTest.java
  19. +3 −3 google-api-client/src/test/java/com/google/api/client/googleapis/batch/BatchRequestTest.java
  20. +2 −2 google-api-client/src/test/java/com/google/api/client/googleapis/compute/ComputeCredentialTest.java
  21. +2 −2 ...-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorContainerTest.java
  22. +2 −2 google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorTest.java
  23. +2 −2 ...ient/src/test/java/com/google/api/client/googleapis/services/AbstractGoogleClientRequestTest.java
  24. +2 −2 ...-api-client/src/test/java/com/google/api/client/googleapis/services/AbstractGoogleClientTest.java
  25. +2 −2 ...nt/src/test/java/com/google/api/client/googleapis/services/json/AbstractGoogleJsonClientTest.java
  26. +2 −2 .../com/google/api/client/googleapis/services/json/CommonGoogleJsonClientRequestInitializerTest.java
  27. +2 −2 .../com/google/api/client/googleapis/testing/json/GoogleJsonResponseExceptionFactoryTestingTest.java
  28. +0 −2 google-api-client/src/test/java/com/google/api/client/googleapis/util/UtilsTest.java
@@ -20,7 +20,7 @@
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import java.io.IOException;
import java.util.Arrays;
@@ -72,7 +72,7 @@ public void testAppEngineCredentialWrapper() throws IOException {
final Collection<String> emptyScopes = Collections.emptyList();

HttpTransport transport = new MockHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();

MockAppIdentityService appIdentity = new MockAppIdentityService();
appIdentity.setAccessTokenText(expectedAccessToken);
@@ -108,7 +108,7 @@ public void testAppEngineCredentialWrapperGetAccessToken() throws IOException {
final String expectedAccessToken = "ExpectedAccessToken";

HttpTransport transport = new MockHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();

MockAppIdentityService appIdentity = new MockAppIdentityService();
appIdentity.setAccessTokenText(expectedAccessToken);
@@ -124,7 +124,7 @@ public void testAppEngineCredentialWrapperGetAccessToken() throws IOException {
}

public void testAppEngineCredentialWrapperNullTransportThrows() throws IOException {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();
try {
new AppIdentityCredential.AppEngineCredentialWrapper(null, jsonFactory);
fail();
@@ -17,21 +17,21 @@
import com.google.api.client.googleapis.notifications.TypedNotificationCallback;
import com.google.api.client.googleapis.notifications.json.JsonNotificationCallback;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.Beta;

/**
* {@link Beta} <br>
* A {@link TypedNotificationCallback} which uses an JSON content encoding with {@link
* JacksonFactory#getDefaultInstance()}.
* GsonFactory#getDefaultInstance()}.
*
* <p>Must NOT be implemented in form of an anonymous class as this will break serialization.
*
* <p>Implementation should be thread-safe. <b>Example usage:</b>
*
* <pre>
* static class MyNotificationCallback
* extends GsonNotificationCallback{@literal <}ListResponse{@literal >} {
* extends JacksonNotificationCallback{@literal <}ListResponse{@literal >} {
*
* private static final long serialVersionUID = 1L;
*
@@ -67,6 +67,6 @@

@Override
protected JsonFactory getJsonFactory() {
return JacksonFactory.getDefaultInstance();
return GsonFactory.getDefaultInstance();
}
}
@@ -121,14 +121,9 @@
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
@@ -43,7 +43,7 @@
* static void requestAccessToken() throws IOException {
* try {
* GoogleTokenResponse response =
* new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),
* new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new GsonFactory(),
* "812741506391.apps.googleusercontent.com", "{client_secret}",
* "4/P7q7W91a-oMsCeLvIaQm6bTrgtp7", "https://oauth2-login-demo.appspot.com/code")
* .execute();
@@ -41,7 +41,7 @@
* static void refreshAccessToken() throws IOException {
* try {
* TokenResponse response =
* new GoogleRefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(),
* new GoogleRefreshTokenRequest(new NetHttpTransport(), new GsonFactory(),
* "tGzv3JOkF0XG5Qx2TlKWIA", "s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw").execute();
* System.out.println("Access token: " + response.getAccessToken());
* } catch (TokenResponseException e) {
@@ -113,7 +113,7 @@
* headers.setApplicationName("Google-YouTubeSample/1.0");
* headers.gdataVersion = "2";
* JsonCParser parser = new JsonCParser();
* parser.jsonFactory = new JacksonFactory();
* parser.jsonFactory = new GsonFactory();
* transport.addParser(parser);
* // insert authentication code...
* return transport;
@@ -51,7 +51,7 @@
*
* {@literal @}Override
* protected ObjectParser getObjectParser(Notification notification) throws IOException {
* return new JsonObjectParser(new JacksonFactory());
* return new JsonObjectParser(new GsonFactory());
* }
*
* {@literal @}Override
@@ -50,7 +50,7 @@
*
* {@literal @}Override
* protected JsonFactory getJsonFactory() throws IOException {
* return new JacksonFactory();
* return new GsonFactory();
* }
*
* {@literal @}Override
@@ -6,7 +6,7 @@
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
@@ -84,7 +84,7 @@ public MockGoogleCredential build() {
setClientAuthentication(new MockClientAuthentication());
}
if (getJsonFactory() == null) {
setJsonFactory(new JacksonFactory());
setJsonFactory(new GsonFactory());
}
return new MockGoogleCredential(this);
}
@@ -21,7 +21,7 @@
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.json.webtoken.JsonWebSignature;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
@@ -47,7 +47,7 @@ public class MockTokenServerTransport extends MockHttpTransport {
private static final Logger LOGGER = Logger.getLogger(MockTokenServerTransport.class.getName());

static final String EXPECTED_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
static final JsonFactory JSON_FACTORY = new JacksonFactory();
static final JsonFactory JSON_FACTORY = new GsonFactory();
final String tokenServerUrl;
Map<String, String> serviceAccounts = new HashMap<String, String>();
Map<String, String> clients = new HashMap<String, String>();
@@ -20,7 +20,7 @@
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
@@ -41,7 +41,7 @@ public class MockMetadataServerTransport extends MockHttpTransport {
private static final String METADATA_TOKEN_SERVER_URL =
METADATA_SERVER_URL + "/computeMetadata/v1/instance/service-accounts/default/token";

static final JsonFactory JSON_FACTORY = new JacksonFactory();
static final JsonFactory JSON_FACTORY = new GsonFactory();

String accessToken;

@@ -17,7 +17,7 @@
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.Beta;

/**
@@ -39,7 +39,7 @@ private static class JsonFactoryInstanceHolder {
// other APIs to not require one of these for input. This was the most commonly used
// implementation in public samples. This is a compile-time dependency to help detect the
// dependency as early as possible.
static final JsonFactory INSTANCE = new JacksonFactory();
static final JsonFactory INSTANCE = new GsonFactory();
}

/** Returns a cached default implementation of the HttpTransport interface. */
@@ -23,7 +23,7 @@
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import java.io.File;
@@ -45,7 +45,7 @@
/** Tests {@link DefaultCredentialProvider}. */
public class DefaultCredentialProviderTest extends TestCase {

private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static final JsonFactory JSON_FACTORY = new GsonFactory();

private static final Collection<String> SCOPES =
Collections.unmodifiableCollection(Arrays.asList("scope1", "scope2"));
@@ -14,7 +14,7 @@

package com.google.api.client.googleapis.auth.oauth2;

import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.common.collect.ImmutableList;
import junit.framework.TestCase;
@@ -33,7 +33,7 @@ public void testBuilder() {
GoogleAuthorizationCodeFlow.Builder builder =
new GoogleAuthorizationCodeFlow.Builder(
new MockHttpTransport(),
new JacksonFactory(),
new GsonFactory(),
CLIENT_ID,
CLIENT_SECRET,
ImmutableList.of("https://www.googleapis.com/auth/userinfo.email"));
@@ -15,7 +15,7 @@
package com.google.api.client.googleapis.auth.oauth2;

import com.google.api.client.auth.oauth2.ClientParametersAuthentication;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import junit.framework.TestCase;

@@ -35,7 +35,7 @@ public void test() {
GoogleAuthorizationCodeTokenRequest request =
new GoogleAuthorizationCodeTokenRequest(
new MockHttpTransport(),
new JacksonFactory(),
new GsonFactory(),
CLIENT_ID,
CLIENT_SECRET,
CODE,
@@ -18,7 +18,7 @@
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.util.SecurityTestUtils;
import java.io.ByteArrayInputStream;
@@ -36,7 +36,7 @@
*/
public class GoogleCredentialTest extends TestCase {

private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static final JsonFactory JSON_FACTORY = new GsonFactory();

private static final Collection<String> SCOPES =
Collections.unmodifiableCollection(Arrays.asList("scope1", "scope2"));
@@ -16,7 +16,7 @@

import com.google.api.client.auth.openidconnect.IdTokenVerifier;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.json.webtoken.JsonWebSignature.Header;
import com.google.api.client.testing.http.FixedClock;
import com.google.api.client.util.Clock;
@@ -52,7 +52,7 @@ public void testBuilder() throws Exception {
GoogleIdTokenVerifier.Builder builder =
new GoogleIdTokenVerifier.Builder(
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(),
new JacksonFactory())
new GsonFactory())
.setIssuer(ISSUER)
.setAudience(TRUSTED_CLIENT_IDS);
assertEquals(Clock.SYSTEM, builder.getClock());
@@ -71,7 +71,7 @@ public void testVerify() throws Exception {
GoogleIdTokenVerifier verifier =
new GoogleIdTokenVerifier.Builder(
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(),
new JacksonFactory())
new GsonFactory())
.build();
Header header = new Header();
header.setAlgorithm("RS25");
@@ -83,7 +83,7 @@ public void testVerify() throws Exception {
assertFalse(verifier.verify(idToken2));
verifier =
new GoogleIdTokenVerifier(
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new JacksonFactory());
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new GsonFactory());
assertFalse(verifier.verify(idToken));
assertFalse(verifier.verify(idToken2));
// TODO(yanivi): add a unit test that returns true
@@ -20,7 +20,7 @@
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.FixedClock;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
@@ -68,7 +68,7 @@ public class GooglePublicKeysManagerTest extends TestCase {

public void testBuilder() throws Exception {
HttpTransport transport = new MockHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();
GooglePublicKeysManager.Builder builder =
new GooglePublicKeysManager.Builder(transport, jsonFactory);

@@ -102,7 +102,7 @@ public LowLevelHttpResponse execute() {
public void testRefresh() throws Exception {
GooglePublicKeysManager certs =
new GooglePublicKeysManager.Builder(
new PublicCertsMockHttpTransport(), new JacksonFactory())
new PublicCertsMockHttpTransport(), new GsonFactory())
.build();
certs.refresh();
assertEquals(2, certs.getPublicKeys().size());
@@ -112,7 +112,7 @@ public void testLoadCerts_cache() throws Exception {
PublicCertsMockHttpTransport transport = new PublicCertsMockHttpTransport();
transport.useAgeHeader = true;
GooglePublicKeysManager certs =
new GooglePublicKeysManager.Builder(transport, new JacksonFactory())
new GooglePublicKeysManager.Builder(transport, new GsonFactory())
.setClock(new FixedClock(100))
.build();

@@ -123,7 +123,7 @@ public void testLoadCerts_cache() throws Exception {

public void testGetCacheTimeInSec() throws Exception {
GooglePublicKeysManager certs =
new GooglePublicKeysManager.Builder(new MockHttpTransport(), new JacksonFactory()).build();
new GooglePublicKeysManager.Builder(new MockHttpTransport(), new GsonFactory()).build();
assertEquals(
12000,
certs.getCacheTimeInSec(
@@ -25,7 +25,7 @@
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.protobuf.ProtoObjectParser;
import com.google.api.client.testing.http.HttpTesting;
import com.google.api.client.testing.http.MockHttpTransport;
@@ -527,7 +527,7 @@ private BatchRequest getBatchPopulatedWithRequests(
credential = new MockCredential();

ObjectParser parser =
testBinary ? new ProtoObjectParser() : new JsonObjectParser(new JacksonFactory());
testBinary ? new ProtoObjectParser() : new JsonObjectParser(new GsonFactory());
BatchRequest batchRequest =
new BatchRequest(transport, credential).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
@@ -629,7 +629,7 @@ public void subTestExecuteWithVoidCallback(boolean testServerError) throws IOExc
new MockGoogleClientRequest<String>(client, METHOD1, URI_TEMPLATE1, null, String.class);
MockGoogleClientRequest<String> jsonHttpRequest2 =
new MockGoogleClientRequest<String>(client, METHOD2, URI_TEMPLATE2, null, String.class);
ObjectParser parser = new JsonObjectParser(new JacksonFactory());
ObjectParser parser = new JsonObjectParser(new GsonFactory());
BatchRequest batchRequest =
new BatchRequest(transport, null).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
@@ -16,7 +16,7 @@

import com.google.api.client.googleapis.testing.compute.MockMetadataServerTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import junit.framework.TestCase;

/**
@@ -32,7 +32,7 @@ public void testExecuteRefreshToken() throws Exception {

HttpTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);

ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory());
ComputeCredential credential = new ComputeCredential(transport, new GsonFactory());

assertTrue(credential.refreshToken());
assertEquals(ACCESS_TOKEN, credential.getAccessToken());

0 comments on commit 63ed2ca

Please sign in to comment.