Skip to content

Commit 63ed2ca

Browse files
authored
fix: use Gson instead of Jackson (#1661)
* use GSon instead of Jackson * remove jackson2 * fix callback
1 parent 8dc6c92 commit 63ed2ca

28 files changed

+57
-64
lines changed

google-api-client-appengine/src/test/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/AppIdentityCredentialTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.google.api.client.http.HttpRequest;
2121
import com.google.api.client.http.HttpTransport;
2222
import com.google.api.client.json.JsonFactory;
23-
import com.google.api.client.json.jackson2.JacksonFactory;
23+
import com.google.api.client.json.gson.GsonFactory;
2424
import com.google.api.client.testing.http.MockHttpTransport;
2525
import java.io.IOException;
2626
import java.util.Arrays;
@@ -72,7 +72,7 @@ public void testAppEngineCredentialWrapper() throws IOException {
7272
final Collection<String> emptyScopes = Collections.emptyList();
7373

7474
HttpTransport transport = new MockHttpTransport();
75-
JsonFactory jsonFactory = new JacksonFactory();
75+
JsonFactory jsonFactory = new GsonFactory();
7676

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

110110
HttpTransport transport = new MockHttpTransport();
111-
JsonFactory jsonFactory = new JacksonFactory();
111+
JsonFactory jsonFactory = new GsonFactory();
112112

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

126126
public void testAppEngineCredentialWrapperNullTransportThrows() throws IOException {
127-
JsonFactory jsonFactory = new JacksonFactory();
127+
JsonFactory jsonFactory = new GsonFactory();
128128
try {
129129
new AppIdentityCredential.AppEngineCredentialWrapper(null, jsonFactory);
130130
fail();

google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/notifications/json/jackson2/JacksonNotificationCallback.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
import com.google.api.client.googleapis.notifications.TypedNotificationCallback;
1818
import com.google.api.client.googleapis.notifications.json.JsonNotificationCallback;
1919
import com.google.api.client.json.JsonFactory;
20-
import com.google.api.client.json.jackson2.JacksonFactory;
20+
import com.google.api.client.json.gson.GsonFactory;
2121
import com.google.api.client.util.Beta;
2222

2323
/**
2424
* {@link Beta} <br>
2525
* A {@link TypedNotificationCallback} which uses an JSON content encoding with {@link
26-
* JacksonFactory#getDefaultInstance()}.
26+
* GsonFactory#getDefaultInstance()}.
2727
*
2828
* <p>Must NOT be implemented in form of an anonymous class as this will break serialization.
2929
*
3030
* <p>Implementation should be thread-safe. <b>Example usage:</b>
3131
*
3232
* <pre>
3333
* static class MyNotificationCallback
34-
* extends GsonNotificationCallback{@literal <}ListResponse{@literal >} {
34+
* extends JacksonNotificationCallback{@literal <}ListResponse{@literal >} {
3535
*
3636
* private static final long serialVersionUID = 1L;
3737
*
@@ -67,6 +67,6 @@ public abstract class JacksonNotificationCallback<T> extends JsonNotificationCal
6767

6868
@Override
6969
protected JsonFactory getJsonFactory() {
70-
return JacksonFactory.getDefaultInstance();
70+
return GsonFactory.getDefaultInstance();
7171
}
7272
}

google-api-client/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,9 @@
121121
<groupId>com.google.oauth-client</groupId>
122122
<artifactId>google-oauth-client</artifactId>
123123
</dependency>
124-
<dependency>
125-
<groupId>com.google.http-client</groupId>
126-
<artifactId>google-http-client-jackson2</artifactId>
127-
</dependency>
128124
<dependency>
129125
<groupId>com.google.http-client</groupId>
130126
<artifactId>google-http-client-gson</artifactId>
131-
<scope>test</scope>
132127
</dependency>
133128
<dependency>
134129
<groupId>com.google.http-client</groupId>

google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeTokenRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* static void requestAccessToken() throws IOException {
4444
* try {
4545
* GoogleTokenResponse response =
46-
* new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),
46+
* new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new GsonFactory(),
4747
* "812741506391.apps.googleusercontent.com", "{client_secret}",
4848
* "4/P7q7W91a-oMsCeLvIaQm6bTrgtp7", "https://oauth2-login-demo.appspot.com/code")
4949
* .execute();

google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleRefreshTokenRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* static void refreshAccessToken() throws IOException {
4242
* try {
4343
* TokenResponse response =
44-
* new GoogleRefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(),
44+
* new GoogleRefreshTokenRequest(new NetHttpTransport(), new GsonFactory(),
4545
* "tGzv3JOkF0XG5Qx2TlKWIA", "s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw").execute();
4646
* System.out.println("Access token: " + response.getAccessToken());
4747
* } catch (TokenResponseException e) {

google-api-client/src/main/java/com/google/api/client/googleapis/json/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
* headers.setApplicationName("Google-YouTubeSample/1.0");
114114
* headers.gdataVersion = "2";
115115
* JsonCParser parser = new JsonCParser();
116-
* parser.jsonFactory = new JacksonFactory();
116+
* parser.jsonFactory = new GsonFactory();
117117
* transport.addParser(parser);
118118
* // insert authentication code...
119119
* return transport;

google-api-client/src/main/java/com/google/api/client/googleapis/notifications/TypedNotificationCallback.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*
5252
* {@literal @}Override
5353
* protected ObjectParser getObjectParser(Notification notification) throws IOException {
54-
* return new JsonObjectParser(new JacksonFactory());
54+
* return new JsonObjectParser(new GsonFactory());
5555
* }
5656
*
5757
* {@literal @}Override

google-api-client/src/main/java/com/google/api/client/googleapis/notifications/json/JsonNotificationCallback.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*
5151
* {@literal @}Override
5252
* protected JsonFactory getJsonFactory() throws IOException {
53-
* return new JacksonFactory();
53+
* return new GsonFactory();
5454
* }
5555
*
5656
* {@literal @}Override

google-api-client/src/main/java/com/google/api/client/googleapis/testing/auth/oauth2/MockGoogleCredential.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.google.api.client.http.HttpTransport;
77
import com.google.api.client.json.Json;
88
import com.google.api.client.json.JsonFactory;
9-
import com.google.api.client.json.jackson2.JacksonFactory;
9+
import com.google.api.client.json.gson.GsonFactory;
1010
import com.google.api.client.testing.http.MockHttpTransport;
1111
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
1212
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
@@ -84,7 +84,7 @@ public MockGoogleCredential build() {
8484
setClientAuthentication(new MockClientAuthentication());
8585
}
8686
if (getJsonFactory() == null) {
87-
setJsonFactory(new JacksonFactory());
87+
setJsonFactory(new GsonFactory());
8888
}
8989
return new MockGoogleCredential(this);
9090
}

google-api-client/src/main/java/com/google/api/client/googleapis/testing/auth/oauth2/MockTokenServerTransport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.google.api.client.json.GenericJson;
2222
import com.google.api.client.json.Json;
2323
import com.google.api.client.json.JsonFactory;
24-
import com.google.api.client.json.jackson2.JacksonFactory;
24+
import com.google.api.client.json.gson.GsonFactory;
2525
import com.google.api.client.json.webtoken.JsonWebSignature;
2626
import com.google.api.client.testing.http.MockHttpTransport;
2727
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
@@ -47,7 +47,7 @@ public class MockTokenServerTransport extends MockHttpTransport {
4747
private static final Logger LOGGER = Logger.getLogger(MockTokenServerTransport.class.getName());
4848

4949
static final String EXPECTED_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
50-
static final JsonFactory JSON_FACTORY = new JacksonFactory();
50+
static final JsonFactory JSON_FACTORY = new GsonFactory();
5151
final String tokenServerUrl;
5252
Map<String, String> serviceAccounts = new HashMap<String, String>();
5353
Map<String, String> clients = new HashMap<String, String>();

google-api-client/src/main/java/com/google/api/client/googleapis/testing/compute/MockMetadataServerTransport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.google.api.client.json.GenericJson;
2121
import com.google.api.client.json.Json;
2222
import com.google.api.client.json.JsonFactory;
23-
import com.google.api.client.json.jackson2.JacksonFactory;
23+
import com.google.api.client.json.gson.GsonFactory;
2424
import com.google.api.client.testing.http.MockHttpTransport;
2525
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2626
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
@@ -41,7 +41,7 @@ public class MockMetadataServerTransport extends MockHttpTransport {
4141
private static final String METADATA_TOKEN_SERVER_URL =
4242
METADATA_SERVER_URL + "/computeMetadata/v1/instance/service-accounts/default/token";
4343

44-
static final JsonFactory JSON_FACTORY = new JacksonFactory();
44+
static final JsonFactory JSON_FACTORY = new GsonFactory();
4545

4646
String accessToken;
4747

google-api-client/src/main/java/com/google/api/client/googleapis/util/Utils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.google.api.client.http.HttpTransport;
1818
import com.google.api.client.http.javanet.NetHttpTransport;
1919
import com.google.api.client.json.JsonFactory;
20-
import com.google.api.client.json.jackson2.JacksonFactory;
20+
import com.google.api.client.json.gson.GsonFactory;
2121
import com.google.api.client.util.Beta;
2222

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

4545
/** Returns a cached default implementation of the HttpTransport interface. */

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/DefaultCredentialProviderTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.google.api.client.http.LowLevelHttpResponse;
2424
import com.google.api.client.json.GenericJson;
2525
import com.google.api.client.json.JsonFactory;
26-
import com.google.api.client.json.jackson2.JacksonFactory;
26+
import com.google.api.client.json.gson.GsonFactory;
2727
import com.google.api.client.testing.http.MockHttpTransport;
2828
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2929
import java.io.File;
@@ -45,7 +45,7 @@
4545
/** Tests {@link DefaultCredentialProvider}. */
4646
public class DefaultCredentialProviderTest extends TestCase {
4747

48-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
48+
private static final JsonFactory JSON_FACTORY = new GsonFactory();
4949

5050
private static final Collection<String> SCOPES =
5151
Collections.unmodifiableCollection(Arrays.asList("scope1", "scope2"));

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeFlowTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

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

17-
import com.google.api.client.json.jackson2.JacksonFactory;
17+
import com.google.api.client.json.gson.GsonFactory;
1818
import com.google.api.client.testing.http.MockHttpTransport;
1919
import com.google.common.collect.ImmutableList;
2020
import junit.framework.TestCase;
@@ -33,7 +33,7 @@ public void testBuilder() {
3333
GoogleAuthorizationCodeFlow.Builder builder =
3434
new GoogleAuthorizationCodeFlow.Builder(
3535
new MockHttpTransport(),
36-
new JacksonFactory(),
36+
new GsonFactory(),
3737
CLIENT_ID,
3838
CLIENT_SECRET,
3939
ImmutableList.of("https://www.googleapis.com/auth/userinfo.email"));

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeTokenRequestTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package com.google.api.client.googleapis.auth.oauth2;
1616

1717
import com.google.api.client.auth.oauth2.ClientParametersAuthentication;
18-
import com.google.api.client.json.jackson2.JacksonFactory;
18+
import com.google.api.client.json.gson.GsonFactory;
1919
import com.google.api.client.testing.http.MockHttpTransport;
2020
import junit.framework.TestCase;
2121

@@ -35,7 +35,7 @@ public void test() {
3535
GoogleAuthorizationCodeTokenRequest request =
3636
new GoogleAuthorizationCodeTokenRequest(
3737
new MockHttpTransport(),
38-
new JacksonFactory(),
38+
new GsonFactory(),
3939
CLIENT_ID,
4040
CLIENT_SECRET,
4141
CODE,

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleCredentialTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.google.api.client.http.HttpTransport;
1919
import com.google.api.client.json.GenericJson;
2020
import com.google.api.client.json.JsonFactory;
21-
import com.google.api.client.json.jackson2.JacksonFactory;
21+
import com.google.api.client.json.gson.GsonFactory;
2222
import com.google.api.client.testing.http.MockHttpTransport;
2323
import com.google.api.client.testing.util.SecurityTestUtils;
2424
import java.io.ByteArrayInputStream;
@@ -36,7 +36,7 @@
3636
*/
3737
public class GoogleCredentialTest extends TestCase {
3838

39-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
39+
private static final JsonFactory JSON_FACTORY = new GsonFactory();
4040

4141
private static final Collection<String> SCOPES =
4242
Collections.unmodifiableCollection(Arrays.asList("scope1", "scope2"));

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GoogleIdTokenVerifierTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import com.google.api.client.auth.openidconnect.IdTokenVerifier;
1818
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
19-
import com.google.api.client.json.jackson2.JacksonFactory;
19+
import com.google.api.client.json.gson.GsonFactory;
2020
import com.google.api.client.json.webtoken.JsonWebSignature.Header;
2121
import com.google.api.client.testing.http.FixedClock;
2222
import com.google.api.client.util.Clock;
@@ -52,7 +52,7 @@ public void testBuilder() throws Exception {
5252
GoogleIdTokenVerifier.Builder builder =
5353
new GoogleIdTokenVerifier.Builder(
5454
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(),
55-
new JacksonFactory())
55+
new GsonFactory())
5656
.setIssuer(ISSUER)
5757
.setAudience(TRUSTED_CLIENT_IDS);
5858
assertEquals(Clock.SYSTEM, builder.getClock());
@@ -71,7 +71,7 @@ public void testVerify() throws Exception {
7171
GoogleIdTokenVerifier verifier =
7272
new GoogleIdTokenVerifier.Builder(
7373
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(),
74-
new JacksonFactory())
74+
new GsonFactory())
7575
.build();
7676
Header header = new Header();
7777
header.setAlgorithm("RS25");
@@ -83,7 +83,7 @@ public void testVerify() throws Exception {
8383
assertFalse(verifier.verify(idToken2));
8484
verifier =
8585
new GoogleIdTokenVerifier(
86-
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new JacksonFactory());
86+
new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new GsonFactory());
8787
assertFalse(verifier.verify(idToken));
8888
assertFalse(verifier.verify(idToken2));
8989
// TODO(yanivi): add a unit test that returns true

google-api-client/src/test/java/com/google/api/client/googleapis/auth/oauth2/GooglePublicKeysManagerTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.google.api.client.http.LowLevelHttpResponse;
2121
import com.google.api.client.json.Json;
2222
import com.google.api.client.json.JsonFactory;
23-
import com.google.api.client.json.jackson2.JacksonFactory;
23+
import com.google.api.client.json.gson.GsonFactory;
2424
import com.google.api.client.testing.http.FixedClock;
2525
import com.google.api.client.testing.http.MockHttpTransport;
2626
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
@@ -68,7 +68,7 @@ public class GooglePublicKeysManagerTest extends TestCase {
6868

6969
public void testBuilder() throws Exception {
7070
HttpTransport transport = new MockHttpTransport();
71-
JsonFactory jsonFactory = new JacksonFactory();
71+
JsonFactory jsonFactory = new GsonFactory();
7272
GooglePublicKeysManager.Builder builder =
7373
new GooglePublicKeysManager.Builder(transport, jsonFactory);
7474

@@ -102,7 +102,7 @@ public LowLevelHttpResponse execute() {
102102
public void testRefresh() throws Exception {
103103
GooglePublicKeysManager certs =
104104
new GooglePublicKeysManager.Builder(
105-
new PublicCertsMockHttpTransport(), new JacksonFactory())
105+
new PublicCertsMockHttpTransport(), new GsonFactory())
106106
.build();
107107
certs.refresh();
108108
assertEquals(2, certs.getPublicKeys().size());
@@ -112,7 +112,7 @@ public void testLoadCerts_cache() throws Exception {
112112
PublicCertsMockHttpTransport transport = new PublicCertsMockHttpTransport();
113113
transport.useAgeHeader = true;
114114
GooglePublicKeysManager certs =
115-
new GooglePublicKeysManager.Builder(transport, new JacksonFactory())
115+
new GooglePublicKeysManager.Builder(transport, new GsonFactory())
116116
.setClock(new FixedClock(100))
117117
.build();
118118

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

124124
public void testGetCacheTimeInSec() throws Exception {
125125
GooglePublicKeysManager certs =
126-
new GooglePublicKeysManager.Builder(new MockHttpTransport(), new JacksonFactory()).build();
126+
new GooglePublicKeysManager.Builder(new MockHttpTransport(), new GsonFactory()).build();
127127
assertEquals(
128128
12000,
129129
certs.getCacheTimeInSec(

google-api-client/src/test/java/com/google/api/client/googleapis/batch/BatchRequestTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.google.api.client.http.LowLevelHttpResponse;
2626
import com.google.api.client.json.GenericJson;
2727
import com.google.api.client.json.JsonObjectParser;
28-
import com.google.api.client.json.jackson2.JacksonFactory;
28+
import com.google.api.client.json.gson.GsonFactory;
2929
import com.google.api.client.protobuf.ProtoObjectParser;
3030
import com.google.api.client.testing.http.HttpTesting;
3131
import com.google.api.client.testing.http.MockHttpTransport;
@@ -527,7 +527,7 @@ private BatchRequest getBatchPopulatedWithRequests(
527527
credential = new MockCredential();
528528

529529
ObjectParser parser =
530-
testBinary ? new ProtoObjectParser() : new JsonObjectParser(new JacksonFactory());
530+
testBinary ? new ProtoObjectParser() : new JsonObjectParser(new GsonFactory());
531531
BatchRequest batchRequest =
532532
new BatchRequest(transport, credential).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
533533
HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
@@ -629,7 +629,7 @@ public void subTestExecuteWithVoidCallback(boolean testServerError) throws IOExc
629629
new MockGoogleClientRequest<String>(client, METHOD1, URI_TEMPLATE1, null, String.class);
630630
MockGoogleClientRequest<String> jsonHttpRequest2 =
631631
new MockGoogleClientRequest<String>(client, METHOD2, URI_TEMPLATE2, null, String.class);
632-
ObjectParser parser = new JsonObjectParser(new JacksonFactory());
632+
ObjectParser parser = new JsonObjectParser(new GsonFactory());
633633
BatchRequest batchRequest =
634634
new BatchRequest(transport, null).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
635635
HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();

google-api-client/src/test/java/com/google/api/client/googleapis/compute/ComputeCredentialTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import com.google.api.client.googleapis.testing.compute.MockMetadataServerTransport;
1818
import com.google.api.client.http.HttpTransport;
19-
import com.google.api.client.json.jackson2.JacksonFactory;
19+
import com.google.api.client.json.gson.GsonFactory;
2020
import junit.framework.TestCase;
2121

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

3333
HttpTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);
3434

35-
ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory());
35+
ComputeCredential credential = new ComputeCredential(transport, new GsonFactory());
3636

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

0 commit comments

Comments
 (0)