File tree 2 files changed +32
-1
lines changed
python/google/protobuf/internal
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):
568
568
)
569
569
)
570
570
571
- if new_val :
571
+ if new_val != None :
572
572
try :
573
573
field_copy .MergeFrom (new_val )
574
574
except TypeError :
Original file line number Diff line number Diff line change 13
13
import datetime
14
14
import unittest
15
15
16
+ from google .protobuf import json_format
16
17
from google .protobuf import text_format
17
18
from google .protobuf .internal import more_messages_pb2
18
19
from google .protobuf .internal import well_known_types
@@ -1040,6 +1041,36 @@ def testPackDeterministic(self):
1040
1041
b'\x0e \x1a \x05 \n \x01 8\x10 \x10 \x1a \x05 \n \x01 9\x10 \x12 ' )
1041
1042
self .assertEqual (golden , serialized )
1042
1043
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
+
1043
1074
1044
1075
if __name__ == '__main__' :
1045
1076
unittest .main ()
You can’t perform that action at this time.
0 commit comments