Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrefilov-piterbyte committed Mar 29, 2016
1 parent 0d32ab3 commit 6f8dd21
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion csharp/protos/unittest_issues.proto
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ message TestJsonFieldOrdering {
}

message TestJsonName {
// json_name field options are not properly handled during deserialization
// Message for testing the effects for of the json_name option
string name = 1;
string description = 2 [json_name = "desc"];
string guid = 3 [json_name = "exid"];
Expand Down
1 change: 1 addition & 0 deletions csharp/src/Google.Protobuf.Test/IssuesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void JsonNameParseTest()
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<TestJsonName>("{ \"name\": \"test\", \"desc\": \"test2\", \"guid\": \"test3\" }"));
}
Expand Down
3 changes: 1 addition & 2 deletions csharp/src/Google.Protobuf/JsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ private bool WriteMessageFields(TextWriter writer, IMessage message, bool assume
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);

Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file,
/// <summary>
/// The json_name option of the descriptor's target.
/// </summary>
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; } }

Expand Down
4 changes: 1 addition & 3 deletions csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ private static ReadOnlyDictionary<string, FieldDescriptor> CreateJsonFieldMap(IL
var map = new Dictionary<string, FieldDescriptor>();
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<string, FieldDescriptor>(map);
}
Expand Down

0 comments on commit 6f8dd21

Please sign in to comment.