File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
python/google/protobuf/internal Expand file tree Collapse file tree 2 files changed +32
-1
lines changed 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 more_messages_pb2
1819from google .protobuf .internal import well_known_types
@@ -1040,6 +1041,36 @@ def testPackDeterministic(self):
10401041 b'\x0e \x1a \x05 \n \x01 8\x10 \x10 \x1a \x05 \n \x01 9\x10 \x12 ' )
10411042 self .assertEqual (golden , serialized )
10421043
1044+ def testJsonStruct (self ):
1045+ value = struct_pb2 .Value (struct_value = struct_pb2 .Struct ())
1046+ value_dict = json_format .MessageToDict (
1047+ value ,
1048+ always_print_fields_with_no_presence = True ,
1049+ preserving_proto_field_name = True ,
1050+ use_integers_for_enums = True ,
1051+ )
1052+ self .assertDictEqual (value_dict , {})
1053+
1054+ s = struct_pb2 .Struct (
1055+ fields = {
1056+ 'a' : struct_pb2 .Value (struct_value = struct_pb2 .Struct ()),
1057+ },
1058+ )
1059+
1060+ sdict = json_format .MessageToDict (
1061+ s ,
1062+ always_print_fields_with_no_presence = True ,
1063+ preserving_proto_field_name = True ,
1064+ use_integers_for_enums = True ,
1065+ )
1066+
1067+ self .assertDictEqual (
1068+ sdict ,
1069+ {
1070+ 'a' : {},
1071+ },
1072+ )
1073+
10431074
10441075if __name__ == '__main__' :
10451076 unittest .main ()
You can’t perform that action at this time.
0 commit comments