File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/Elastic.Clients.Elasticsearch.Shared/Types Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information.
44
5+ using System ;
6+ using System . Text . Json ;
7+ using System . Text . Json . Serialization ;
8+
59using Elastic . Transport ;
610
711#if ELASTICSEARCH_SERVERLESS
@@ -10,6 +14,7 @@ namespace Elastic.Clients.Elasticsearch.Serverless;
1014namespace Elastic . Clients . Elasticsearch ;
1115#endif
1216
17+ [ JsonConverter ( typeof ( OpTypeConverter ) ) ]
1318public partial struct OpType : IStringable
1419{
1520 public static OpType Index = new ( "index" ) ;
@@ -23,3 +28,26 @@ public partial struct OpType : IStringable
2328
2429 public string GetString ( ) => Value ?? string . Empty ;
2530}
31+
32+ internal sealed class OpTypeConverter :
33+ JsonConverter < OpType >
34+ {
35+ public override OpType Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
36+ {
37+ if ( reader . TokenType != JsonTokenType . String )
38+ {
39+ throw new JsonException ( "Unexpected token." ) ;
40+ }
41+
42+ var value = reader . GetString ( ) ;
43+
44+ return value switch
45+ {
46+ "index" => OpType . Index ,
47+ "create" => OpType . Create ,
48+ _ => throw new JsonException ( $ "Unsupported value '{ value } ' for '{ nameof ( OpType ) } ' enum.")
49+ } ;
50+ }
51+
52+ public override void Write ( Utf8JsonWriter writer , OpType value , JsonSerializerOptions options ) => writer . WriteStringValue ( value . Value ) ;
53+ }
You can’t perform that action at this time.
0 commit comments