@@ -87,14 +87,45 @@ public sealed partial class CreateRequestParameters : RequestParameters
87
87
public Elastic . Clients . Elasticsearch . WaitForActiveShards ? WaitForActiveShards { get => Q < Elastic . Clients . Elasticsearch . WaitForActiveShards ? > ( "wait_for_active_shards" ) ; set => Q ( "wait_for_active_shards" , value ) ; }
88
88
}
89
89
90
+ internal sealed partial class CreateRequestConverter < TDocument > : System . Text . Json . Serialization . JsonConverter < CreateRequest < TDocument > >
91
+ {
92
+ public override CreateRequest < TDocument > Read ( ref System . Text . Json . Utf8JsonReader reader , System . Type typeToConvert , System . Text . Json . JsonSerializerOptions options )
93
+ {
94
+ return new CreateRequest < TDocument > { Document = reader . ReadValue < TDocument > ( options , typeof ( SourceMarker < TDocument > ) ) } ;
95
+ }
96
+
97
+ public override void Write ( System . Text . Json . Utf8JsonWriter writer , CreateRequest < TDocument > value , System . Text . Json . JsonSerializerOptions options )
98
+ {
99
+ writer . WriteValue ( options , value . Document , typeof ( SourceMarker < TDocument > ) ) ;
100
+ }
101
+ }
102
+
103
+ internal sealed partial class CreateRequestConverterFactory : System . Text . Json . Serialization . JsonConverterFactory
104
+ {
105
+ public override bool CanConvert ( System . Type typeToConvert )
106
+ {
107
+ return typeToConvert . IsGenericType && typeToConvert . GetGenericTypeDefinition ( ) == typeof ( CreateRequest < > ) ;
108
+ }
109
+
110
+ public override System . Text . Json . Serialization . JsonConverter CreateConverter ( System . Type typeToConvert , System . Text . Json . JsonSerializerOptions options )
111
+ {
112
+ var args = typeToConvert . GetGenericArguments ( ) ;
113
+ #pragma warning disable IL3050
114
+ var converter = ( System . Text . Json . Serialization . JsonConverter ) System . Activator . CreateInstance ( typeof ( CreateRequestConverter < > ) . MakeGenericType ( args [ 0 ] ) , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . Public , binder : null , args : null , culture : null ) ! ;
115
+ #pragma warning restore IL3050
116
+ return converter ;
117
+ }
118
+ }
119
+
90
120
/// <summary>
91
121
/// <para>
92
122
/// Index a document.
93
123
/// Adds a JSON document to the specified data stream or index and makes it searchable.
94
124
/// If the target is an index and the document already exists, the request updates the document and increments its version.
95
125
/// </para>
96
126
/// </summary>
97
- public sealed partial class CreateRequest < TDocument > : PlainRequest < CreateRequestParameters > , ISelfTwoWaySerializable
127
+ [ JsonConverter ( typeof ( CreateRequestConverterFactory ) ) ]
128
+ public sealed partial class CreateRequest < TDocument > : PlainRequest < CreateRequestParameters >
98
129
{
99
130
public CreateRequest ( Elastic . Clients . Elasticsearch . IndexName index , Elastic . Clients . Elasticsearch . Id id ) : base ( r => r . Required ( "index" , index ) . Required ( "id" , id ) )
100
131
{
@@ -118,7 +149,6 @@ internal CreateRequest()
118
149
/// Unique identifier for the document.
119
150
/// </para>
120
151
/// </summary>
121
- [ JsonIgnore ]
122
152
public Elastic . Clients . Elasticsearch . Id Id { get => P < Elastic . Clients . Elasticsearch . Id > ( "id" ) ; set => PR ( "id" , value ) ; }
123
153
124
154
/// <summary>
@@ -128,7 +158,6 @@ internal CreateRequest()
128
158
/// If the target doesn’t exist and doesn’t match a data stream template, this request creates the index.
129
159
/// </para>
130
160
/// </summary>
131
- [ JsonIgnore ]
132
161
public Elastic . Clients . Elasticsearch . IndexName Index { get => P < Elastic . Clients . Elasticsearch . IndexName > ( "index" ) ; set => PR ( "index" , value ) ; }
133
162
134
163
/// <summary>
@@ -138,7 +167,6 @@ internal CreateRequest()
138
167
/// If a final pipeline is configured it will always run, regardless of the value of this parameter.
139
168
/// </para>
140
169
/// </summary>
141
- [ JsonIgnore ]
142
170
public string ? Pipeline { get => Q < string ? > ( "pipeline" ) ; set => Q ( "pipeline" , value ) ; }
143
171
144
172
/// <summary>
@@ -147,23 +175,20 @@ internal CreateRequest()
147
175
/// Valid values: <c>true</c>, <c>false</c>, <c>wait_for</c>.
148
176
/// </para>
149
177
/// </summary>
150
- [ JsonIgnore ]
151
178
public Elastic . Clients . Elasticsearch . Refresh ? Refresh { get => Q < Elastic . Clients . Elasticsearch . Refresh ? > ( "refresh" ) ; set => Q ( "refresh" , value ) ; }
152
179
153
180
/// <summary>
154
181
/// <para>
155
182
/// Custom value used to route operations to a specific shard.
156
183
/// </para>
157
184
/// </summary>
158
- [ JsonIgnore ]
159
185
public Elastic . Clients . Elasticsearch . Routing ? Routing { get => Q < Elastic . Clients . Elasticsearch . Routing ? > ( "routing" ) ; set => Q ( "routing" , value ) ; }
160
186
161
187
/// <summary>
162
188
/// <para>
163
189
/// Period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards.
164
190
/// </para>
165
191
/// </summary>
166
- [ JsonIgnore ]
167
192
public Elastic . Clients . Elasticsearch . Duration ? Timeout { get => Q < Elastic . Clients . Elasticsearch . Duration ? > ( "timeout" ) ; set => Q ( "timeout" , value ) ; }
168
193
169
194
/// <summary>
@@ -172,15 +197,13 @@ internal CreateRequest()
172
197
/// The specified version must match the current version of the document for the request to succeed.
173
198
/// </para>
174
199
/// </summary>
175
- [ JsonIgnore ]
176
200
public long ? Version { get => Q < long ? > ( "version" ) ; set => Q ( "version" , value ) ; }
177
201
178
202
/// <summary>
179
203
/// <para>
180
204
/// Specific version type: <c>external</c>, <c>external_gte</c>.
181
205
/// </para>
182
206
/// </summary>
183
- [ JsonIgnore ]
184
207
public Elastic . Clients . Elasticsearch . VersionType ? VersionType { get => Q < Elastic . Clients . Elasticsearch . VersionType ? > ( "version_type" ) ; set => Q ( "version_type" , value ) ; }
185
208
186
209
/// <summary>
@@ -189,19 +212,8 @@ internal CreateRequest()
189
212
/// Set to <c>all</c> or any positive integer up to the total number of shards in the index (<c>number_of_replicas+1</c>).
190
213
/// </para>
191
214
/// </summary>
192
- [ JsonIgnore ]
193
215
public Elastic . Clients . Elasticsearch . WaitForActiveShards ? WaitForActiveShards { get => Q < Elastic . Clients . Elasticsearch . WaitForActiveShards ? > ( "wait_for_active_shards" ) ; set => Q ( "wait_for_active_shards" , value ) ; }
194
216
public TDocument Document { get ; set ; }
195
-
196
- void ISelfTwoWaySerializable . Serialize ( Utf8JsonWriter writer , JsonSerializerOptions options , IElasticsearchClientSettings settings )
197
- {
198
- settings . SourceSerializer . Serialize ( Document , writer ) ;
199
- }
200
-
201
- void ISelfTwoWaySerializable . Deserialize ( ref Utf8JsonReader reader , JsonSerializerOptions options , IElasticsearchClientSettings settings )
202
- {
203
- Document = settings . SourceSerializer . Deserialize < TDocument > ( ref reader ) ;
204
- }
205
217
}
206
218
207
219
/// <summary>
0 commit comments