diff options
Diffstat (limited to 'csharp/src/Google.Protobuf')
-rw-r--r-- | csharp/src/Google.Protobuf/JsonFormatter.cs | 7 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs | 6 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs | 2 |
3 files changed, 13 insertions, 2 deletions
diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index eb959c9f..1b5349e9 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -237,11 +237,14 @@ namespace Google.Protobuf { writer.Write(PropertySeparator); } - WriteString(writer, ToCamelCase(accessor.Descriptor.Name)); + + WriteString(writer, string.IsNullOrEmpty(accessor.Descriptor.JsonName) ? + ToCamelCase(accessor.Descriptor.Name) : 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..8cfdb779 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; } } + 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..63f168ca 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -104,6 +104,8 @@ namespace Google.Protobuf.Reflection { map[JsonFormatter.ToCamelCase(field.Name)] = field; map[field.Name] = field; + if (!string.IsNullOrEmpty(field.JsonName)) + map[field.JsonName] = field; } return new ReadOnlyDictionary<string, FieldDescriptor>(map); } |