From 6f8dd2115b3ed07819a48dfa78b15770dfa2c450 Mon Sep 17 00:00:00 2001 From: alien Date: Tue, 29 Mar 2016 20:56:32 +0300 Subject: Code review fixes --- csharp/src/Google.Protobuf.Test/IssuesTest.cs | 1 + csharp/src/Google.Protobuf/JsonFormatter.cs | 3 +-- csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs | 2 +- csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs | 4 +--- 4 files changed, 4 insertions(+), 6 deletions(-) (limited to 'csharp/src') diff --git a/csharp/src/Google.Protobuf.Test/IssuesTest.cs b/csharp/src/Google.Protobuf.Test/IssuesTest.cs index 5b432edf..a38d6b08 100644 --- a/csharp/src/Google.Protobuf.Test/IssuesTest.cs +++ b/csharp/src/Google.Protobuf.Test/IssuesTest.cs @@ -66,6 +66,7 @@ namespace Google.Protobuf var settings = new JsonParser.Settings(10, TypeRegistry.FromFiles(UnittestIssuesReflection.Descriptor)); var parser = new JsonParser(settings); + // It is safe to use either original field name or explicitly specified json_name Assert.AreEqual(new TestJsonName { Name = "test", Description = "test2", Guid = "test3" }, parser.Parse("{ \"name\": \"test\", \"desc\": \"test2\", \"guid\": \"test3\" }")); } diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 1b5349e9..cbd9366c 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -238,8 +238,7 @@ namespace Google.Protobuf writer.Write(PropertySeparator); } - WriteString(writer, string.IsNullOrEmpty(accessor.Descriptor.JsonName) ? - ToCamelCase(accessor.Descriptor.Name) : accessor.Descriptor.JsonName); + WriteString(writer, accessor.Descriptor.JsonName); writer.Write(NameValueSeparator); WriteValue(writer, value); diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 8cfdb779..6083f171 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -94,7 +94,7 @@ namespace Google.Protobuf.Reflection /// /// The json_name option of the descriptor's target. /// - public string JsonName { get { return proto.JsonName; } } + public string JsonName { get { return proto.JsonName == "" ? JsonFormatter.ToCamelCase(proto.Name) : proto.JsonName; } } internal FieldDescriptorProto Proto { get { return proto; } } diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 63f168ca..f5a835e5 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -102,10 +102,8 @@ namespace Google.Protobuf.Reflection var map = new Dictionary(); foreach (var field in fields) { - map[JsonFormatter.ToCamelCase(field.Name)] = field; map[field.Name] = field; - if (!string.IsNullOrEmpty(field.JsonName)) - map[field.JsonName] = field; + map[field.JsonName] = field; } return new ReadOnlyDictionary(map); } -- cgit v1.2.3