diff options
author | Erik Benoist <erik@reverb.com> | 2018-05-22 10:14:04 -0500 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2018-05-25 13:03:30 -0700 |
commit | c19fcee48f064c6a49d865374c3adb37daa3f0dd (patch) | |
tree | 257f081e01c5939666b55e90f7e2dd70a2795e7e /ruby/tests | |
parent | 5289ee0c2139b691111037806f088e306a31ac70 (diff) |
Allows the json marshaller to be passed json marshal options (#4252)
Diffstat (limited to 'ruby/tests')
-rw-r--r-- | ruby/tests/encode_decode_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/ruby/tests/encode_decode_test.rb b/ruby/tests/encode_decode_test.rb index 09581ab0..2bd9b98b 100644 --- a/ruby/tests/encode_decode_test.rb +++ b/ruby/tests/encode_decode_test.rb @@ -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 |