Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
50342e48
Commit
50342e48
authored
Jan 31, 2019
by
Peter Sobot
Committed by
Jie Luo
Jan 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allowed json_format.ParseDict to parse extensions with scalar types. (#5609)
parent
8532804b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
json_format_test.py
python/google/protobuf/internal/json_format_test.py
+11
-0
json_format.py
python/google/protobuf/json_format.py
+4
-1
No files found.
python/google/protobuf/internal/json_format_test.py
View file @
50342e48
...
...
@@ -202,6 +202,17 @@ class JsonFormatTest(JsonFormatBase):
json_format
.
ParseDict
(
message_dict
,
parsed_message
)
self
.
assertEqual
(
message
,
parsed_message
)
def
testExtensionToDictAndBackWithScalar
(
self
):
message
=
unittest_pb2
.
TestAllExtensions
()
ext1
=
unittest_pb2
.
TestNestedExtension
.
test
message
.
Extensions
[
ext1
]
=
'data'
message_dict
=
json_format
.
MessageToDict
(
message
)
parsed_message
=
unittest_pb2
.
TestAllExtensions
()
json_format
.
ParseDict
(
message_dict
,
parsed_message
)
self
.
assertEqual
(
message
,
parsed_message
)
def
testJsonParseDictToAnyDoesNotAlterInput
(
self
):
orig_dict
=
{
'int32Value'
:
20
,
...
...
python/google/protobuf/json_format.py
View file @
50342e48
...
...
@@ -564,7 +564,10 @@ class _Parser(object):
sub_message
.
SetInParent
()
self
.
ConvertMessage
(
value
,
sub_message
)
else
:
setattr
(
message
,
field
.
name
,
_ConvertScalarFieldValue
(
value
,
field
))
if
field
.
is_extension
:
message
.
Extensions
[
field
]
=
_ConvertScalarFieldValue
(
value
,
field
)
else
:
setattr
(
message
,
field
.
name
,
_ConvertScalarFieldValue
(
value
,
field
))
except
ParseError
as
e
:
if
field
and
field
.
containing_oneof
is
None
:
raise
ParseError
(
'Failed to parse {0} field: {1}'
.
format
(
name
,
e
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment