public override TMessage?Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var message = new TMessage(); if (reader.TokenType != JsonTokenType.String) { throw new InvalidOperationException("Expected string value for FieldMask."); } // TODO: Do we *want* to remove empty entries? Probably okay to treat "" as "no paths", but "foo,,bar"? // Note: This logic replicates Google.Protobuf. Should follow their lead. var jsonPaths = reader.GetString() !.Split(',', StringSplitOptions.RemoveEmptyEntries); var messagePaths = (IList)message.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(message); foreach (var path in jsonPaths) { messagePaths.Add(Legacy.ToSnakeCase(path)); } return(message); }