Skip to content

Commit 1c95321

Browse files
committed
Minor adjustments
1 parent c223ca3 commit 1c95321

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/Elastic.Clients.Elasticsearch/_Shared/Core/LazyJsonConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Text.Json;
78
using System.Text.Json.Serialization;
89

@@ -14,13 +15,13 @@ public sealed class LazyJsonConverter : JsonConverter<LazyJson>
1415
{
1516
private IElasticsearchClientSettings? _settings;
1617

18+
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute'", Justification = "Always using explicit TypeInfoResolver")]
19+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute'", Justification = "Always using explicit TypeInfoResolver")]
1720
public override LazyJson Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
1821
{
1922
InitializeSettings(options);
2023

21-
#pragma warning disable IL2026, IL3050 // The `TypeInfoResolver` for `RequestResponseConverter` knows how to handle `JsonElement`.
2224
return new LazyJson(JsonSerializer.Deserialize<JsonElement>(ref reader, options), _settings!);
23-
#pragma warning restore IL2026, IL3050
2425
}
2526

2627
private void InitializeSettings(JsonSerializerOptions options)

src/Elastic.Clients.Elasticsearch/_Shared/Next/JsonWriterExtensions.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,28 @@ public static void WriteUnionValue<T1, T2>(this Utf8JsonWriter writer, JsonSeria
250250
);
251251
}
252252

253-
public static void WriteSpanValue<T>(this Utf8JsonWriter writer, JsonSerializerOptions options, ReadOnlySpan<T> span,
253+
public static void WriteMemoryValue<T>(this Utf8JsonWriter writer, JsonSerializerOptions options, ReadOnlyMemory<T> memory,
254254
JsonWriteFunc<T>? writeElement)
255255
{
256-
writeElement ??= static (w, o, v) => WriteValue(w, o, v);
256+
if (writeElement is null)
257+
{
258+
var converter = options.GetConverter<T>(null);
259+
260+
writeElement = (w, o, v) =>
261+
{
262+
if ((v is null) && !converter.HandleNull)
263+
{
264+
w.WriteNullValue();
265+
return;
266+
}
267+
268+
converter.Write(w, v, o);
269+
};
270+
}
257271

258272
writer.WriteStartArray();
259273

274+
var span = memory.Span;
260275
foreach (var element in span)
261276
{
262277
writeElement(writer, options, element);

src/Elastic.Clients.Elasticsearch/_Shared/Next/VectorConverters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override void Write(Utf8JsonWriter writer, ReadOnlyMemory<float> value, J
5757
switch (_encoding)
5858
{
5959
case FloatVectorDataEncoding.Legacy:
60-
writer.WriteSpanValue(options, value.Span, null);
60+
writer.WriteMemoryValue(options, value, null);
6161
break;
6262

6363
case FloatVectorDataEncoding.Base64:
@@ -192,7 +192,7 @@ public override void Write(Utf8JsonWriter writer, ReadOnlyMemory<byte> value, Js
192192
switch (_encoding)
193193
{
194194
case ByteVectorDataEncoding.Legacy:
195-
writer.WriteSpanValue(options, value.Span, (w, _, b) => w.WriteNumberValue(unchecked((sbyte)b)));
195+
writer.WriteMemoryValue(options, value, (w, _, b) => w.WriteNumberValue(unchecked((sbyte)b)));
196196
break;
197197

198198
case ByteVectorDataEncoding.Hex:

0 commit comments

Comments
 (0)