diff options
author | Dave Protasowski <dprotaso@gmail.com> | 2016-09-08 13:31:46 -0400 |
---|---|---|
committer | Dave Protasowski <dprotaso@gmail.com> | 2016-09-08 15:08:30 -0400 |
commit | 1fc416be21983a024c9e90f43e13152395643b04 (patch) | |
tree | 58c17925e0f494fb3b66a3c5b2852a1533fee27b /java/util/src/test | |
parent | 4bc16578537495b5ee010d89f2909858312210ac (diff) | |
download | protobuf-1fc416be21983a024c9e90f43e13152395643b04.tar.gz protobuf-1fc416be21983a024c9e90f43e13152395643b04.tar.bz2 protobuf-1fc416be21983a024c9e90f43e13152395643b04.zip |
Allow the JsonFormat.Parser to ignore unknown fields
The default behaviour of throwing an exception remains
Diffstat (limited to 'java/util/src/test')
-rw-r--r-- | java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index 6fc784ef..c11114c0 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -1030,6 +1030,22 @@ public class JsonFormatTest extends TestCase { } } + public void testParserUnknownFields() throws Exception { + try { + TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + String json = "{\n" + " \"unknownField\": \"XXX\"\n" + "}"; + JsonFormat.parser().merge(json, builder); + fail("Exception is expected."); + } catch (InvalidProtocolBufferException e) { + // Expected. + } + } + public void testParserIgnoringUnknownFields() throws Exception { + TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + String json = "{\n" + " \"unknownField\": \"XXX\"\n" + "}"; + JsonFormat.parser().ignoringUnknownFields().merge(json, builder); + } + public void testCustomJsonName() throws Exception { TestCustomJsonName message = TestCustomJsonName.newBuilder().setValue(12345).build(); assertEquals("{\n" + " \"@value\": 12345\n" + "}", JsonFormat.printer().print(message)); |