Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

deps: switch from Jackson to GSON #368

Merged
merged 2 commits into from Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google-cloud-core/pom.xml
Expand Up @@ -65,7 +65,7 @@
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<artifactId>google-http-client-gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down