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
a8e23593
Commit
a8e23593
authored
May 22, 2018
by
Erik Benoist
Committed by
Paul Yang
May 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows the json marshaller to be passed json marshal options (#4252)
parent
dd2dc0f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
4 deletions
+28
-4
protobuf.rb
ruby/lib/google/protobuf.rb
+2
-2
message_exts.rb
ruby/lib/google/protobuf/message_exts.rb
+2
-2
encode_decode_test.rb
ruby/tests/encode_decode_test.rb
+24
-0
No files found.
ruby/lib/google/protobuf.rb
View file @
a8e23593
...
...
@@ -60,8 +60,8 @@ module Google
msg
.
to_proto
end
def
self
.
encode_json
(
msg
)
msg
.
to_json
def
self
.
encode_json
(
msg
,
options
=
{}
)
msg
.
to_json
(
options
)
end
def
self
.
decode
(
klass
,
proto
)
...
...
ruby/lib/google/protobuf/message_exts.rb
View file @
a8e23593
...
...
@@ -40,8 +40,8 @@ module Google
module
ClassMethods
end
def
to_json
self
.
class
.
encode_json
(
self
)
def
to_json
(
options
=
{})
self
.
class
.
encode_json
(
self
,
options
)
end
def
to_proto
...
...
ruby/tests/encode_decode_test.rb
View file @
a8e23593
...
...
@@ -60,4 +60,28 @@ class EncodeDecodeTest < Test::Unit::TestCase
to
=
A
::
B
::
C
::
TestMessage
.
encode
(
m
.
oneof_msg
)
assert_equal
''
,
to
end
def
test_encode_json
msg
=
A
::
B
::
C
::
TestMessage
.
new
({
optional_int32:
22
})
json
=
msg
.
to_json
to
=
A
::
B
::
C
::
TestMessage
.
decode_json
(
json
)
assert_equal
to
.
optional_int32
,
22
msg
=
A
::
B
::
C
::
TestMessage
.
new
({
optional_int32:
22
})
json
=
msg
.
to_json
({
preserve_proto_fieldnames:
true
})
assert_match
'optional_int32'
,
json
to
=
A
::
B
::
C
::
TestMessage
.
decode_json
(
json
)
assert_equal
22
,
to
.
optional_int32
msg
=
A
::
B
::
C
::
TestMessage
.
new
({
optional_int32:
22
})
json
=
A
::
B
::
C
::
TestMessage
.
encode_json
(
msg
,
{
preserve_proto_fieldnames:
true
,
emit_defaults:
true
}
)
assert_match
'optional_int32'
,
json
end
end
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