From 136ac18f1fe63440a1f194e50ab6284a94481893 Mon Sep 17 00:00:00 2001 From: yirutang Date: Wed, 22 Dec 2021 10:25:21 -0800 Subject: [PATCH 1/3] fix: allow all fields to be null values --- .../cloud/bigquery/storage/v1/JsonToProtoMessage.java | 3 --- .../bigquery/storage/v1/JsonToProtoMessageTest.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java index 6423fe43f7..20a6d1669f 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java @@ -154,9 +154,6 @@ private static DynamicMessage convertJsonToProtoMessageImpl( String.format( "JSONObject does not have the required field %s.%s.", jsonScope, missingFieldName)); } - if (topLevel && msg.getSerializedSize() == 0) { - throw new IllegalArgumentException("The created protobuf message is empty."); - } return msg; } diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java index 96b46ed8d0..e4ac486bb2 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java @@ -1121,4 +1121,15 @@ public void testJsonNullValue() throws Exception { JsonToProtoMessage.convertJsonToProtoMessage(TestInt64.getDescriptor(), json); assertEquals(expectedProto, protoMsg); } + + @Test + public void testJsonAllFieldsNullValue() throws Exception { + TestInt64 expectedProto = TestInt64.newBuilder().build(); + JSONObject json = new JSONObject(); + json.put("long", JSONObject.NULL); + json.put("int", JSONObject.NULL); + DynamicMessage protoMsg = + JsonToProtoMessage.convertJsonToProtoMessage(TestInt64.getDescriptor(), json); + assertEquals(expectedProto, protoMsg); + } } From 24d805c0d8af4d0ed22f69ba757376630487c515 Mon Sep 17 00:00:00 2001 From: yirutang Date: Wed, 22 Dec 2021 10:42:15 -0800 Subject: [PATCH 2/3] fix tests --- .../bigquery/storage/v1/JsonToProtoMessageTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java index e4ac486bb2..017c45f1e4 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessageTest.java @@ -1033,13 +1033,9 @@ public void testEmptyProtoMessage() throws Exception { JSONObject json = new JSONObject(); json.put("test_repeated", new JSONArray(new int[0])); - try { - DynamicMessage protoMsg = - JsonToProtoMessage.convertJsonToProtoMessage(RepeatedInt64.getDescriptor(), json); - Assert.fail("Should fail"); - } catch (IllegalArgumentException e) { - assertEquals("The created protobuf message is empty.", e.getMessage()); - } + DynamicMessage protoMsg = + JsonToProtoMessage.convertJsonToProtoMessage(RepeatedInt64.getDescriptor(), json); + assertEquals(protoMsg.getAllFields().size(), 0); } @Test From b35a97afa9aa27d9be971b31d89fb16bad6a1bfa Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 23 Dec 2021 16:25:29 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12792a10b6..8fd23d2c2d 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies ```Groovy -implementation platform('com.google.cloud:libraries-bom:24.1.0') +implementation platform('com.google.cloud:libraries-bom:24.1.1') implementation 'com.google.cloud:google-cloud-bigquerystorage' ```