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
37b5617d
Unverified
Commit
37b5617d
authored
Sep 03, 2018
by
Feng Xiao
Committed by
GitHub
Sep 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5099 from oqton/feature/issue-5806
Fixes JSON Loading of Any messages with Unknown Fields in C++
parents
d340bdf5
52870ad8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletion
+41
-1
protostream_objectwriter.cc
...google/protobuf/util/internal/protostream_objectwriter.cc
+13
-1
protostream_objectwriter.h
src/google/protobuf/util/internal/protostream_objectwriter.h
+5
-0
json_util_test.cc
src/google/protobuf/util/json_util_test.cc
+23
-0
No files found.
src/google/protobuf/util/internal/protostream_objectwriter.cc
View file @
37b5617d
...
@@ -73,6 +73,18 @@ ProtoStreamObjectWriter::ProtoStreamObjectWriter(
...
@@ -73,6 +73,18 @@ ProtoStreamObjectWriter::ProtoStreamObjectWriter(
set_use_lower_camel_for_enums
(
options_
.
use_lower_camel_for_enums
);
set_use_lower_camel_for_enums
(
options_
.
use_lower_camel_for_enums
);
}
}
ProtoStreamObjectWriter
::
ProtoStreamObjectWriter
(
const
TypeInfo
*
typeinfo
,
const
google
::
protobuf
::
Type
&
type
,
strings
::
ByteSink
*
output
,
ErrorListener
*
listener
,
const
ProtoStreamObjectWriter
::
Options
&
options
)
:
ProtoWriter
(
typeinfo
,
type
,
output
,
listener
),
master_type_
(
type
),
current_
(
nullptr
),
options_
(
options
)
{
set_ignore_unknown_fields
(
options_
.
ignore_unknown_fields
);
set_use_lower_camel_for_enums
(
options
.
use_lower_camel_for_enums
);
}
ProtoStreamObjectWriter
::
ProtoStreamObjectWriter
(
ProtoStreamObjectWriter
::
ProtoStreamObjectWriter
(
const
TypeInfo
*
typeinfo
,
const
google
::
protobuf
::
Type
&
type
,
const
TypeInfo
*
typeinfo
,
const
google
::
protobuf
::
Type
&
type
,
strings
::
ByteSink
*
output
,
ErrorListener
*
listener
)
strings
::
ByteSink
*
output
,
ErrorListener
*
listener
)
...
@@ -342,7 +354,7 @@ void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) {
...
@@ -342,7 +354,7 @@ void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) {
// Create our object writer and initialize it with the first StartObject
// Create our object writer and initialize it with the first StartObject
// call.
// call.
ow_
.
reset
(
new
ProtoStreamObjectWriter
(
parent_
->
typeinfo
(),
*
type
,
&
output_
,
ow_
.
reset
(
new
ProtoStreamObjectWriter
(
parent_
->
typeinfo
(),
*
type
,
&
output_
,
parent_
->
listener
()));
parent_
->
listener
()
,
parent_
->
options_
));
// Don't call StartObject() for well-known types yet. Depending on the
// Don't call StartObject() for well-known types yet. Depending on the
// type of actual data, we may not need to call StartObject(). For
// type of actual data, we may not need to call StartObject(). For
...
...
src/google/protobuf/util/internal/protostream_objectwriter.h
View file @
37b5617d
...
@@ -323,6 +323,11 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
...
@@ -323,6 +323,11 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
const
google
::
protobuf
::
Type
&
type
,
const
google
::
protobuf
::
Type
&
type
,
strings
::
ByteSink
*
output
,
ErrorListener
*
listener
);
strings
::
ByteSink
*
output
,
ErrorListener
*
listener
);
ProtoStreamObjectWriter
(
const
TypeInfo
*
typeinfo
,
const
google
::
protobuf
::
Type
&
type
,
strings
::
ByteSink
*
output
,
ErrorListener
*
listener
,
const
ProtoStreamObjectWriter
::
Options
&
options
);
// Returns true if the field is a map.
// Returns true if the field is a map.
inline
bool
IsMap
(
const
google
::
protobuf
::
Field
&
field
);
inline
bool
IsMap
(
const
google
::
protobuf
::
Field
&
field
);
...
...
src/google/protobuf/util/json_util_test.cc
View file @
37b5617d
...
@@ -56,6 +56,7 @@ using proto3::TestEnumValue;
...
@@ -56,6 +56,7 @@ using proto3::TestEnumValue;
using
proto3
::
TestMap
;
using
proto3
::
TestMap
;
using
proto3
::
TestMessage
;
using
proto3
::
TestMessage
;
using
proto3
::
TestOneof
;
using
proto3
::
TestOneof
;
using
proto3
::
TestAny
;
static
const
char
kTypeUrlPrefix
[]
=
"type.googleapis.com"
;
static
const
char
kTypeUrlPrefix
[]
=
"type.googleapis.com"
;
...
@@ -357,6 +358,28 @@ TEST_F(JsonUtilTest, TestDynamicMessage) {
...
@@ -357,6 +358,28 @@ TEST_F(JsonUtilTest, TestDynamicMessage) {
EXPECT_EQ
(
ToJson
(
generated
,
options
),
ToJson
(
*
message
,
options
));
EXPECT_EQ
(
ToJson
(
generated
,
options
),
ToJson
(
*
message
,
options
));
}
}
TEST_F
(
JsonUtilTest
,
TestParsingUnknownAnyFields
)
{
string
input
=
"{
\n
"
"
\"
value
\"
: {
\n
"
"
\"
@type
\"
:
\"
type.googleapis.com/proto3.TestMessage
\"
,
\n
"
"
\"
unknown_field
\"
:
\"
UNKOWN_VALUE
\"
,
\n
"
"
\"
string_value
\"
:
\"
expected_value
\"\n
"
" }
\n
"
"}"
;
TestAny
m
;
JsonParseOptions
options
;
EXPECT_FALSE
(
FromJson
(
input
,
&
m
,
options
));
options
.
ignore_unknown_fields
=
true
;
EXPECT_TRUE
(
FromJson
(
input
,
&
m
,
options
));
TestMessage
t
;
EXPECT_TRUE
(
m
.
value
().
UnpackTo
(
&
t
));
EXPECT_EQ
(
"expected_value"
,
t
.
string_value
());
}
TEST_F
(
JsonUtilTest
,
TestParsingUnknownEnumsProto2
)
{
TEST_F
(
JsonUtilTest
,
TestParsingUnknownEnumsProto2
)
{
string
input
=
string
input
=
"{
\n
"
"{
\n
"
...
...
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