diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2017-03-09 16:30:15 -0800 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2017-03-09 16:30:15 -0800 |
commit | 61e87f3d41554989883e2c2fe35fbb9d891879cd (patch) | |
tree | b0232bf1c6fe824e90fb7729cde74e87d30e7f64 /src/google/protobuf/util/internal/protostream_objectwriter_test.cc | |
parent | cad6a51a30d021bc25932f3d0f98b4593463a0c6 (diff) |
Use per-type table to lookup JSON name.
Different fields from different messages can map to the same JSON name
and the original global lookup table is only capable of mapping one of
such fields. This change converts the global table to per-type tables
so fields from different messages won't conflict.
Diffstat (limited to 'src/google/protobuf/util/internal/protostream_objectwriter_test.cc')
-rw-r--r-- | src/google/protobuf/util/internal/protostream_objectwriter_test.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc index a9b15e68..97ef8fff 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -74,6 +74,8 @@ using google::protobuf::testing::Primitive; using google::protobuf::testing::Proto3Message; using google::protobuf::testing::Publisher; using google::protobuf::testing::StructType; +using google::protobuf::testing::TestJsonName1; +using google::protobuf::testing::TestJsonName2; using google::protobuf::testing::TimestampDuration; using google::protobuf::testing::ValueWrapper; using google::protobuf::testing::oneofs::OneOfsRequest; @@ -271,6 +273,26 @@ TEST_P(ProtoStreamObjectWriterTest, CustomJsonName) { CheckOutput(book); } +// Test that two messages can have different fields mapped to the same JSON +// name. See: https://github.com/google/protobuf/issues/1415 +TEST_P(ProtoStreamObjectWriterTest, ConflictingJsonName) { + ResetTypeInfo(TestJsonName1::descriptor()); + TestJsonName1 message1; + message1.set_one_value(12345); + ow_->StartObject("") + ->RenderInt32("value", 12345) + ->EndObject(); + CheckOutput(message1); + + ResetTypeInfo(TestJsonName2::descriptor()); + TestJsonName2 message2; + message2.set_another_value(12345); + ow_->StartObject("") + ->RenderInt32("value", 12345) + ->EndObject(); + CheckOutput(message2); +} + TEST_P(ProtoStreamObjectWriterTest, IntEnumValuesAreAccepted) { Book book; book.set_title("Some Book"); |