Skip to content

Commit

Permalink
[Task]: Replace JacksonFactory references with GsonFactory apache#32130
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonHead1001001 committed Aug 11, 2024
1 parent 4889969 commit be64a84
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#Sat Aug 10 17:06:24 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.storage.Storage;
import com.google.auth.Credentials;
Expand Down Expand Up @@ -53,7 +54,7 @@ private static class SingletonHelper {

static {
try {
JSON_FACTORY = JacksonFactory.getDefaultInstance();
JSON_FACTORY = GsonFactory.getDefaultInstance();
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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.HttpTesting;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
Expand Down Expand Up @@ -474,7 +474,7 @@ public void testRetryFileSizeNonBatch() throws IOException {

@Test
public void testGetSizeBytesWhenFileNotFoundBatch() throws Exception {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();

String contentBoundary = "batch_foobarbaz";
String contentBoundaryLine = "--" + contentBoundary;
Expand Down Expand Up @@ -545,7 +545,7 @@ public void testGetSizeBytesWhenFileNotFoundNoBatch() throws Exception {

@Test
public void testGetSizeBytesWhenFileNotFoundBatchRetry() throws Exception {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();

String contentBoundary = "batch_foobarbaz";
String contentBoundaryLine = "--" + contentBoundary;
Expand Down Expand Up @@ -657,7 +657,7 @@ public LowLevelHttpResponse execute() throws IOException {

@Test
public void testRemoveWhenFileNotFound() throws Exception {
JsonFactory jsonFactory = new JacksonFactory();
JsonFactory jsonFactory = new GsonFactory();

String contentBoundary = "batch_foobarbaz";
String contentBoundaryLine = "--" + contentBoundary;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ private void verifyMetricWasSet(
/** Builds a fake GoogleJsonResponseException for testing API error handling. */
private static GoogleJsonResponseException googleJsonResponseException(
final int status, final String reason, final String message) throws IOException {
final JsonFactory jsonFactory = new JacksonFactory();
final JsonFactory jsonFactory = new GsonFactory();
HttpTransport transport =
new MockHttpTransport() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.google.api.client.http.LowLevelHttpRequest;
import com.google.api.client.http.LowLevelHttpResponse;
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.services.storage.Storage;
import java.io.IOException;
import org.apache.beam.sdk.metrics.Histogram;
Expand All @@ -61,7 +61,7 @@ public class LatencyRecordingHttpRequestInitializerTest {
@Mock private LowLevelHttpResponse mockLowLevelResponse;
@Mock private Histogram mockHistogram;

private final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
private final JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
private Storage storage;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.google.api.client.http.LowLevelHttpRequest;
import com.google.api.client.http.LowLevelHttpResponse;
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;
Expand Down Expand Up @@ -79,7 +79,7 @@ public class RetryHttpRequestInitializerTest {
@Mock private LowLevelHttpResponse mockLowLevelResponse;
@Mock private HttpResponseInterceptor mockHttpResponseInterceptor;

private final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
private final JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
private Storage storage;

// Used to test retrying a request more than the default 10 times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.PatientEverything;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages;
Expand Down Expand Up @@ -736,7 +735,7 @@ private void initClient() throws IOException {

client =
new CloudHealthcare.Builder(
new NetHttpTransport(), new JacksonFactory(), requestInitializer)
new NetHttpTransport(), new GsonFactory(), requestInitializer)
.setApplicationName("apache-beam-hl7v2-io")
.build();
httpClient =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.Json;
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.util.MockSleeper;
Expand Down Expand Up @@ -1597,12 +1597,12 @@ public void testSkipInvalidRowsIgnoreUnknownIgnoreInsertIdsValuesStreaming()
/** A helper to convert a string response back to a {@link GenericJson} subclass. */
private static <T extends GenericJson> T fromString(String content, Class<T> clazz)
throws IOException {
return JacksonFactory.getDefaultInstance().fromString(content, clazz);
return GsonFactory.getDefaultInstance().fromString(content, clazz);
}

/** A helper to wrap a {@link GenericJson} object in a content stream. */
private static InputStream toStream(GenericJson content) throws IOException {
return new ByteArrayInputStream(JacksonFactory.getDefaultInstance().toByteArray(content));
return new ByteArrayInputStream(GsonFactory.getDefaultInstance().toByteArray(content));
}

/** A helper that generates the error JSON payload that Google APIs produce. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.healthcare.v1.model.HttpBody;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.StorageObject;
Expand Down Expand Up @@ -136,7 +136,7 @@ public static void tearDownTempBucket() throws IOException {
request.setReadTimeout(60000); // 1 minute read timeout
};
Storage storage =
new Storage.Builder(new NetHttpTransport(), new JacksonFactory(), requestInitializer)
new Storage.Builder(new NetHttpTransport(), new GsonFactory(), requestInitializer)
.build();
List<StorageObject> blobs = storage.objects().list(DEFAULT_TEMP_BUCKET).execute().getItems();
if (blobs != null) {
Expand Down

0 comments on commit be64a84

Please sign in to comment.