From ba57a4e71500231c5834ea322f4ce1b8b530fac4 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 18 Dec 2023 15:42:12 -0800 Subject: [PATCH] Add optional fields also to the testing PiperOrigin-RevId: 592030444 --- src/google/protobuf/json/json_test.cc | 8 +++++++- src/google/protobuf/util/json_format_proto3.proto | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/json/json_test.cc b/src/google/protobuf/json/json_test.cc index 2ff1e87a90..aac3ed7dd0 100644 --- a/src/google/protobuf/json/json_test.cc +++ b/src/google/protobuf/json/json_test.cc @@ -204,6 +204,9 @@ TEST_P(JsonTest, TestDefaultValues) { m.set_string_value("i am a test string value"); m.set_bytes_value("i am a test bytes value"); + m.set_optional_bool_value(false); + m.set_optional_string_value(""); + m.set_optional_bytes_value(""); EXPECT_THAT( ToJson(m, options), IsOkAndHolds("{\"boolValue\":false," @@ -226,7 +229,10 @@ TEST_P(JsonTest, TestDefaultValues) { "\"repeatedStringValue\":[]," "\"repeatedBytesValue\":[]," "\"repeatedEnumValue\":[]," - "\"repeatedMessageValue\":[]" + "\"repeatedMessageValue\":[]," + "\"optionalBoolValue\":false," + "\"optionalStringValue\":\"\"," + "\"optionalBytesValue\":\"\"" "}")); EXPECT_THAT( diff --git a/src/google/protobuf/util/json_format_proto3.proto b/src/google/protobuf/util/json_format_proto3.proto index 8818adc6ea..e631c2a193 100644 --- a/src/google/protobuf/util/json_format_proto3.proto +++ b/src/google/protobuf/util/json_format_proto3.proto @@ -54,6 +54,18 @@ message TestMessage { repeated bytes repeated_bytes_value = 29; repeated EnumType repeated_enum_value = 30; repeated MessageType repeated_message_value = 31; + + optional bool optional_bool_value = 41; + optional int32 optional_int32_value = 42; + optional int64 optional_int64_value = 43; + optional uint32 optional_uint32_value = 44; + optional uint64 optional_uint64_value = 45; + optional float optional_float_value = 46; + optional double optional_double_value = 47; + optional string optional_string_value = 48; + optional bytes optional_bytes_value = 49; + optional EnumType optional_enum_value = 50; + optional MessageType optional_message_value = 51; } message TestOneof {