diff --git a/java-core/google-cloud-core/pom.xml b/java-core/google-cloud-core/pom.xml
index 176fe2a18b..e297d4633b 100644
--- a/java-core/google-cloud-core/pom.xml
+++ b/java-core/google-cloud-core/pom.xml
@@ -65,7 +65,7 @@
com.google.http-client
- google-http-client-jackson2
+ google-http-client-gson
com.google.protobuf
diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
index 2a84403af0..7891088d34 100644
--- a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
+++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
@@ -30,8 +30,7 @@
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser;
-import com.google.api.client.json.jackson2.JacksonFactory;
-import com.google.api.client.util.Charsets;
+import com.google.api.client.json.gson.GsonFactory;
import com.google.api.core.ApiClock;
import com.google.api.core.BetaApi;
import com.google.api.core.CurrentMillisClock;
@@ -61,6 +60,7 @@
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@@ -516,19 +516,18 @@ protected static String getServiceAccountProjectId() {
@InternalApi("Visible for testing")
static String getValueFromCredentialsFile(String credentialsPath, String key) {
- String value = null;
if (credentialsPath != null) {
try (InputStream credentialsStream = new FileInputStream(credentialsPath)) {
- JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
+ JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
GenericJson fileContents =
- parser.parseAndClose(credentialsStream, Charsets.UTF_8, GenericJson.class);
- value = (String) fileContents.get(key);
- } catch (IOException e) {
- // ignore
+ parser.parseAndClose(credentialsStream, StandardCharsets.UTF_8, GenericJson.class);
+ return (String) fileContents.get(key);
+ } catch (IOException | IllegalArgumentException ex) {
+ return null;
}
}
- return value;
+ return null;
}
/**
diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java
index 6f8763c84b..bf75fca161 100644
--- a/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java
+++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java
@@ -45,6 +45,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
@@ -441,9 +442,11 @@ public void testGetServiceAccountProjectId() throws Exception {
public void testGetServiceAccountProjectId_badJson() throws Exception {
File credentialsFile = File.createTempFile("credentials", ".json");
credentialsFile.deleteOnExit();
- Files.write("asdfghj".getBytes(), credentialsFile);
+ Files.write("asdfghj".getBytes(StandardCharsets.UTF_8), credentialsFile);
- assertNull(ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id"));
+ String valueFromCredentialsFile =
+ ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id");
+ assertNull(valueFromCredentialsFile);
}
@Test