File tree Expand file tree Collapse file tree
python/google/protobuf/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -568,7 +568,7 @@ def init(self, **kwargs):
568568 )
569569 )
570570
571- if new_val :
571+ if new_val != None :
572572 try :
573573 field_copy .MergeFrom (new_val )
574574 except TypeError :
Original file line number Diff line number Diff line change 1313import datetime
1414import unittest
1515
16+ from google .protobuf import json_format
1617from google .protobuf import text_format
1718from google .protobuf .internal import any_test_pb2
1819from google .protobuf .internal import more_messages_pb2
@@ -1038,6 +1039,36 @@ def testPackDeterministic(self):
10381039 b'\x0e \x1a \x05 \n \x01 8\x10 \x10 \x1a \x05 \n \x01 9\x10 \x12 ' )
10391040 self .assertEqual (golden , serialized )
10401041
1042+ def testJsonStruct (self ):
1043+ value = struct_pb2 .Value (struct_value = struct_pb2 .Struct ())
1044+ value_dict = json_format .MessageToDict (
1045+ value ,
1046+ always_print_fields_with_no_presence = True ,
1047+ preserving_proto_field_name = True ,
1048+ use_integers_for_enums = True ,
1049+ )
1050+ self .assertDictEqual (value_dict , {})
1051+
1052+ s = struct_pb2 .Struct (
1053+ fields = {
1054+ 'a' : struct_pb2 .Value (struct_value = struct_pb2 .Struct ()),
1055+ },
1056+ )
1057+
1058+ sdict = json_format .MessageToDict (
1059+ s ,
1060+ always_print_fields_with_no_presence = True ,
1061+ preserving_proto_field_name = True ,
1062+ use_integers_for_enums = True ,
1063+ )
1064+
1065+ self .assertDictEqual (
1066+ sdict ,
1067+ {
1068+ 'a' : {},
1069+ },
1070+ )
1071+
10411072
10421073if __name__ == '__main__' :
10431074 unittest .main ()
You can’t perform that action at this time.
0 commit comments