Skip to content

Commit 924b330

Browse files
authored
deps: switch from Jackson to GSON (#368)
* switch from Jackson to GSON * format
1 parent 78905ad commit 924b330

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

java-core/google-cloud-core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</dependency>
6666
<dependency>
6767
<groupId>com.google.http-client</groupId>
68-
<artifactId>google-http-client-jackson2</artifactId>
68+
<artifactId>google-http-client-gson</artifactId>
6969
</dependency>
7070
<dependency>
7171
<groupId>com.google.protobuf</groupId>

java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
import com.google.api.client.json.GenericJson;
3131
import com.google.api.client.json.JsonFactory;
3232
import com.google.api.client.json.JsonObjectParser;
33-
import com.google.api.client.json.jackson2.JacksonFactory;
34-
import com.google.api.client.util.Charsets;
33+
import com.google.api.client.json.gson.GsonFactory;
3534
import com.google.api.core.ApiClock;
3635
import com.google.api.core.BetaApi;
3736
import com.google.api.core.CurrentMillisClock;
@@ -61,6 +60,7 @@
6160
import java.io.ObjectInputStream;
6261
import java.io.Serializable;
6362
import java.nio.charset.Charset;
63+
import java.nio.charset.StandardCharsets;
6464
import java.util.Locale;
6565
import java.util.Map;
6666
import java.util.Objects;
@@ -516,19 +516,18 @@ protected static String getServiceAccountProjectId() {
516516

517517
@InternalApi("Visible for testing")
518518
static String getValueFromCredentialsFile(String credentialsPath, String key) {
519-
String value = null;
520519
if (credentialsPath != null) {
521520
try (InputStream credentialsStream = new FileInputStream(credentialsPath)) {
522-
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
521+
JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
523522
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
524523
GenericJson fileContents =
525-
parser.parseAndClose(credentialsStream, Charsets.UTF_8, GenericJson.class);
526-
value = (String) fileContents.get(key);
527-
} catch (IOException e) {
528-
// ignore
524+
parser.parseAndClose(credentialsStream, StandardCharsets.UTF_8, GenericJson.class);
525+
return (String) fileContents.get(key);
526+
} catch (IOException | IllegalArgumentException ex) {
527+
return null;
529528
}
530529
}
531-
return value;
530+
return null;
532531
}
533532

534533
/**

java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.File;
4646
import java.io.IOException;
4747
import java.io.InputStream;
48+
import java.nio.charset.StandardCharsets;
4849
import java.util.Map;
4950
import java.util.Set;
5051
import java.util.regex.Pattern;
@@ -441,9 +442,11 @@ public void testGetServiceAccountProjectId() throws Exception {
441442
public void testGetServiceAccountProjectId_badJson() throws Exception {
442443
File credentialsFile = File.createTempFile("credentials", ".json");
443444
credentialsFile.deleteOnExit();
444-
Files.write("asdfghj".getBytes(), credentialsFile);
445+
Files.write("asdfghj".getBytes(StandardCharsets.UTF_8), credentialsFile);
445446

446-
assertNull(ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id"));
447+
String valueFromCredentialsFile =
448+
ServiceOptions.getValueFromCredentialsFile(credentialsFile.getPath(), "project_id");
449+
assertNull(valueFromCredentialsFile);
447450
}
448451

449452
@Test

0 commit comments

Comments
 (0)