diff options
| author | Erik Benoist <ebenoist@gmail.com> | 2018-11-17 16:50:24 -0600 |
|---|---|---|
| committer | Erik Benoist <ebenoist@gmail.com> | 2018-12-21 16:06:21 -0600 |
| commit | 9ac11326dfc75c829e530c9a255b9f2a0e19f1d9 (patch) | |
| tree | fa98f62535c64538fc36227e22f53ef477e296a3 /ruby/tests/basic.rb | |
| parent | 436139803ffbe0ca3dc0e563b63f29b2fd729d4f (diff) | |
| download | platform_external_protobuf-9ac11326dfc75c829e530c9a255b9f2a0e19f1d9.tar.gz platform_external_protobuf-9ac11326dfc75c829e530c9a255b9f2a0e19f1d9.tar.bz2 platform_external_protobuf-9ac11326dfc75c829e530c9a255b9f2a0e19f1d9.zip | |
Adds the ability to ignore unknown fields on parse
This adds the ability for the MRI Ruby library to optionally pass in a
ignore_unknown_fields option when decoding JSON. The functionality was
added upstream in upb, this change exposes that option.
Diffstat (limited to 'ruby/tests/basic.rb')
| -rw-r--r-- | ruby/tests/basic.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 77dfead40..5e17bef65 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -254,6 +254,19 @@ module BasicTest "b" => TestMessage2.new(:foo => 2)} end + def test_protobuf_decode_json_ignore_unknown_fields + m = TestMessage.decode_json({ + optional_string: "foo", + not_in_message: "some_value" + }.to_json, { ignore_unknown_fields: true }) + + assert_equal m.optional_string, "foo" + e = assert_raise Google::Protobuf::ParseError do + TestMessage.decode_json({ not_in_message: "some_value" }.to_json) + end + assert_match(/No such field: not_in_message/, e.message) + end + def test_to_h m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)]) expected_result = { |
