aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf')
-rw-r--r--csharp/src/Google.Protobuf/JsonFormatter.cs6
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs6
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs2
3 files changed, 11 insertions, 3 deletions
diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs
index eb959c9f..cbd9366c 100644
--- a/csharp/src/Google.Protobuf/JsonFormatter.cs
+++ b/csharp/src/Google.Protobuf/JsonFormatter.cs
@@ -237,11 +237,13 @@ namespace Google.Protobuf
{
writer.Write(PropertySeparator);
}
- WriteString(writer, ToCamelCase(accessor.Descriptor.Name));
+
+ WriteString(writer, accessor.Descriptor.JsonName);
writer.Write(NameValueSeparator);
WriteValue(writer, value);
+
first = false;
- }
+ }
return !first;
}
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
index c6caaec6..6083f171 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -90,6 +90,12 @@ namespace Google.Protobuf.Reflection
/// </summary>
public override string Name { get { return proto.Name; } }
+
+ /// <summary>
+ /// The json_name option of the descriptor's target.
+ /// </summary>
+ public string JsonName { get { return proto.JsonName == "" ? JsonFormatter.ToCamelCase(proto.Name) : proto.JsonName; } }
+
internal FieldDescriptorProto Proto { get { return proto; } }
/// <summary>
diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
index f5798d1e..f5a835e5 100644
--- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -102,8 +102,8 @@ namespace Google.Protobuf.Reflection
var map = new Dictionary<string, FieldDescriptor>();
foreach (var field in fields)
{
- map[JsonFormatter.ToCamelCase(field.Name)] = field;
map[field.Name] = field;
+ map[field.JsonName] = field;
}
return new ReadOnlyDictionary<string, FieldDescriptor>(map);
}