Commit f22be4dd authored by giokara-oqton's avatar giokara-oqton Committed by Jie Luo

fix json_format.ParseDict modifies input (#5267)

* fix json_format.ParseDict modifies input

* added unit test

* fix naming
parent 9313cdc4
......@@ -200,6 +200,16 @@ class JsonFormatTest(JsonFormatBase):
json_format.ParseDict(message_dict, parsed_message)
self.assertEqual(message, parsed_message)
def testJsonParseDictToAnyDoesNotAlterInput(self):
orig_dict = {
"int32Value": 20,
"@type": "type.googleapis.com/proto3.TestMessage"
}
copied_dict = json.loads(json.dumps(orig_dict))
parsed_message = any_pb2.Any()
json_format.ParseDict(copied_dict, parsed_message)
self.assertEqual(copied_dict, orig_dict)
def testExtensionSerializationDictMatchesProto3Spec(self):
"""See go/proto3-json-spec for spec.
"""
......
......@@ -573,6 +573,7 @@ class _Parser(object):
else:
del value['@type']
self._ConvertFieldValuePair(value, sub_message)
value['@type'] = type_url
# Sets Any message
message.value = sub_message.SerializeToString()
message.type_url = type_url
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment