@@ -241,53 +241,18 @@ public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? prov
241
241
#endregion IParsable
242
242
}
243
243
244
- internal sealed class IndicesJsonConverter : JsonConverter < Indices >
244
+ internal sealed class IndicesJsonConverter :
245
+ JsonConverter < Indices >
245
246
{
246
- private IElasticsearchClientSettings _settings ;
247
-
248
- public override Indices ? Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
247
+ public override Indices Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
249
248
{
250
- if ( reader . TokenType == JsonTokenType . String )
251
- {
252
- Indices indices = reader . GetString ( ) ;
253
- return indices ;
254
- }
255
- else if ( reader . TokenType == JsonTokenType . StartArray )
256
- {
257
- var indices = new List < string > ( ) ;
258
- while ( reader . Read ( ) && reader . TokenType != JsonTokenType . EndArray )
259
- {
260
- var index = reader . GetString ( ) ;
261
- indices . Add ( index ) ;
262
- }
263
- return new Indices ( indices ) ;
264
- }
249
+ var indices = reader . ReadSingleOrManyCollectionValue < IndexName > ( options , null ) ! ;
265
250
266
- reader . Read ( ) ;
267
- return null ;
251
+ return new Indices ( indices ) ;
268
252
}
269
253
270
254
public override void Write ( Utf8JsonWriter writer , Indices value , JsonSerializerOptions options )
271
255
{
272
- InitializeSettings ( options ) ;
273
-
274
- if ( value == null )
275
- {
276
- writer . WriteNullValue ( ) ;
277
- return ;
278
- }
279
-
280
- writer . WriteStringValue ( ( ( IUrlParameter ) value ) . GetString ( _settings ) ) ;
281
- }
282
-
283
- private void InitializeSettings ( JsonSerializerOptions options )
284
- {
285
- if ( _settings is null )
286
- {
287
- if ( ! options . TryGetClientSettings ( out var settings ) )
288
- ThrowHelper . ThrowJsonExceptionForMissingSettings ( ) ;
289
-
290
- _settings = settings ;
291
- }
256
+ writer . WriteSingleOrManyCollectionValue ( options , value . IndexNames , null ) ;
292
257
}
293
258
}
0 commit comments