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
c12cc349
Commit
c12cc349
authored
Mar 17, 2017
by
Jie Luo
Committed by
GitHub
Mar 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2837 from anandolee/master
DefaultValueObjectWriter should populate oneof message field
parents
6b27c1f9
d59592af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
default_value_objectwriter.cc
...ogle/protobuf/util/internal/default_value_objectwriter.cc
+3
-2
json_util_test.cc
src/google/protobuf/util/json_util_test.cc
+16
-0
No files found.
src/google/protobuf/util/internal/default_value_objectwriter.cc
View file @
c12cc349
...
...
@@ -363,8 +363,9 @@ void DefaultValueObjectWriter::Node::PopulateChildren(
}
// If oneof_index() != 0, the child field is part of a "oneof", which means
// the child field is optional and we shouldn't populate its default value.
if
(
field
.
oneof_index
()
!=
0
)
continue
;
// the child field is optional and we shouldn't populate its default
// primitive value.
if
(
field
.
oneof_index
()
!=
0
&&
kind
==
PRIMITIVE
)
continue
;
// If the child field is of primitive type, sets its data to the default
// value of its type.
...
...
src/google/protobuf/util/json_util_test.cc
View file @
c12cc349
...
...
@@ -51,6 +51,7 @@ using proto3::FOO;
using
proto3
::
BAR
;
using
proto3
::
TestMessage
;
using
proto3
::
TestMap
;
using
proto3
::
TestOneof
;
using
testing
::
MapIn
;
static
const
char
kTypeUrlPrefix
[]
=
"type.googleapis.com"
;
...
...
@@ -232,6 +233,21 @@ TEST_F(JsonUtilTest, ParsePrimitiveMapIn) {
EXPECT_EQ
(
message
.
DebugString
(),
other
.
DebugString
());
}
TEST_F
(
JsonUtilTest
,
PrintPrimitiveOneof
)
{
TestOneof
message
;
JsonPrintOptions
options
;
options
.
always_print_primitive_fields
=
true
;
message
.
mutable_oneof_message_value
();
EXPECT_EQ
(
"{
\"
oneofMessageValue
\"
:{
\"
value
\"
:0}}"
,
ToJson
(
message
,
options
));
message
.
set_oneof_int32_value
(
1
);
EXPECT_EQ
(
"{
\"
oneofInt32Value
\"
:1}"
,
ToJson
(
message
,
options
));
}
TEST_F
(
JsonUtilTest
,
TestParseIgnoreUnknownFields
)
{
TestMessage
m
;
JsonParseOptions
options
;
...
...
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