-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple expand_wildcards (#5317)
Since 7.10.1 the watcher expand_wildcards property has accepted and returns an array for expanded_wildcards. This broke in our existing representation of IndicesOptions during deserialisation. This change is breaking but now supports either a single string value or an array in the JSON response.
- Loading branch information
1 parent
9251068
commit 35c12cd
Showing
4 changed files
with
771 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Elasticsearch.Net; | ||
using Elasticsearch.Net.Utf8Json; | ||
|
||
namespace Nest | ||
{ | ||
internal class ExpandWildcardsFormatter : IJsonFormatter<IEnumerable<ExpandWildcards>> | ||
{ | ||
public IEnumerable<ExpandWildcards> Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) | ||
{ | ||
var token = reader.GetCurrentJsonToken(); | ||
return token == JsonToken.BeginArray | ||
? formatterResolver.GetFormatter<IEnumerable<ExpandWildcards>>().Deserialize(ref reader, formatterResolver) | ||
: new[] { formatterResolver.GetFormatter<ExpandWildcards>().Deserialize(ref reader, formatterResolver) }; | ||
} | ||
|
||
public void Serialize(ref JsonWriter writer, IEnumerable<ExpandWildcards> value, IJsonFormatterResolver formatterResolver) | ||
{ | ||
if (value == null) | ||
{ | ||
writer.WriteNull(); | ||
return; | ||
} | ||
|
||
var wildcards = value.ToArray(); | ||
|
||
switch (wildcards.Length) | ||
{ | ||
case 1: | ||
var singleFormatter = formatterResolver.GetFormatter<ExpandWildcards>(); | ||
singleFormatter.Serialize(ref writer, wildcards.First(), formatterResolver); | ||
break; | ||
case > 1: | ||
var formatter = formatterResolver.GetFormatter<IEnumerable<ExpandWildcards>>(); | ||
formatter.Serialize(ref writer, wildcards, formatterResolver); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.