Index: third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs |
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs |
index d1732b2ecb6fe0a8d5d4fe9b8c385dd26b8db96d..f5a835e5ccb50126e3cdb25d12e0a4892ff9b0ca 100644 |
--- a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs |
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs |
@@ -60,7 +60,7 @@ namespace Google.Protobuf.Reflection |
private readonly IList<FieldDescriptor> fieldsInNumberOrder; |
private readonly IDictionary<string, FieldDescriptor> jsonFieldMap; |
- internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo) |
+ internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo) |
: base(file, file.ComputeFullName(parent, proto.Name), typeIndex) |
{ |
Proto = proto; |
@@ -92,11 +92,22 @@ namespace Google.Protobuf.Reflection |
new FieldDescriptor(field, file, this, index, generatedCodeInfo?.PropertyNames[index])); |
fieldsInNumberOrder = new ReadOnlyCollection<FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray()); |
// TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.) |
- jsonFieldMap = new ReadOnlyDictionary<string, FieldDescriptor>(fieldsInNumberOrder.ToDictionary(field => JsonFormatter.ToCamelCase(field.Name))); |
+ jsonFieldMap = CreateJsonFieldMap(fieldsInNumberOrder); |
file.DescriptorPool.AddSymbol(this); |
Fields = new FieldCollection(this); |
} |
+ private static ReadOnlyDictionary<string, FieldDescriptor> CreateJsonFieldMap(IList<FieldDescriptor> fields) |
+ { |
+ var map = new Dictionary<string, FieldDescriptor>(); |
+ foreach (var field in fields) |
+ { |
+ map[field.Name] = field; |
+ map[field.JsonName] = field; |
+ } |
+ return new ReadOnlyDictionary<string, FieldDescriptor>(map); |
+ } |
+ |
/// <summary> |
/// The brief name of the descriptor's target. |
/// </summary> |
@@ -255,9 +266,10 @@ namespace Google.Protobuf.Reflection |
// TODO: consider making this public in the future. (Being conservative for now...) |
/// <value> |
- /// Returns a read-only dictionary mapping the field names in this message as they're used |
+ /// Returns a read-only dictionary mapping the field names in this message as they're available |
/// in the JSON representation to the field descriptors. For example, a field <c>foo_bar</c> |
- /// in the message would result in an entry with a key <c>fooBar</c>. |
+ /// in the message would result two entries, one with a key <c>fooBar</c> and one with a key |
+ /// <c>foo_bar</c>, both referring to the same field. |
/// </value> |
internal IDictionary<string, FieldDescriptor> ByJsonName() => messageDescriptor.jsonFieldMap; |