diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2015-08-26 13:33:50 -0700 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2015-08-26 13:33:50 -0700 |
commit | 042bfaf67f07ab7f277d35a5e654d101d980e202 (patch) | |
tree | 1471754e2b1f78300a9165ce856b61c07d42ec6d | |
parent | 11e36b1c39d5bee92c7a0d76e95523987af5c312 (diff) | |
parent | b00595a3a9411cd54ab303a7ecbde0369d59cac1 (diff) |
Merge remote-tracking branch 'origin/master' into beta-1
-rw-r--r-- | src/google/protobuf/util/internal/protostream_objectwriter.cc | 4 | ||||
-rw-r--r-- | src/google/protobuf/util/json_util_test.cc | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index 28779301..a935ac39 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -1602,8 +1602,10 @@ bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) { const google::protobuf::Type* field_type = typeinfo_->GetTypeByTypeUrl(field.type_url()); + // TODO(xiaofeng): Unify option names. return GetBoolOptionOrDefault(field_type->options(), - "google.protobuf.MessageOptions.map_entry", false); + "google.protobuf.MessageOptions.map_entry", false) || + GetBoolOptionOrDefault(field_type->options(), "map_entry", false); } void ProtoStreamObjectWriter::WriteTag(const google::protobuf::Field& field) { diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 7f88e672..f4dc3562 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -47,6 +47,7 @@ namespace { using proto3::FOO; using proto3::BAR; using proto3::TestMessage; +using proto3::TestMap; static const char kTypeUrlPrefix[] = "type.googleapis.com"; @@ -147,6 +148,16 @@ TEST_F(JsonUtilTest, ParseMessage) { EXPECT_EQ(96, m.repeated_message_value(1).value()); } +TEST_F(JsonUtilTest, ParseMap) { + TestMap message; + (*message.mutable_string_map())["hello"] = 1234; + JsonOptions options; + EXPECT_EQ("{\"stringMap\":{\"hello\":1234}}", ToJson(message, options)); + TestMap other; + ASSERT_TRUE(FromJson(ToJson(message, options), &other)); + EXPECT_EQ(message.DebugString(), other.DebugString()); +} + typedef pair<char*, int> Segment; // A ZeroCopyOutputStream that writes to multiple buffers. class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { |