Merge pull request #709 from xfxyjwf/map_bug

Fix JSON map fields parsing.
This commit is contained in:
Feng Xiao 2015-08-26 13:18:04 -07:00
commit b00595a3a9
2 changed files with 14 additions and 1 deletions

View File

@ -1541,8 +1541,10 @@ bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) {
const google::protobuf::Type* field_type =
typeinfo_->GetType(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) {

View File

@ -47,6 +47,7 @@ namespace {
using proto3::FOO;
using proto3::BAR;
using proto3::TestMessage;
using proto3::TestMap;
static const char kTypeUrlPrefix[] = "type.googleapis.com";
@ -146,6 +147,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 {