Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Microsoft.Data.SqlClient;

/// <summary>
/// Source-generated JSON metadata. Each <c>[JsonSerializable]</c> type gets a property named after its CLR type:
/// <c>float[]</c> -> <c>SingleArray</c>, <c>ReadOnlyMemory&lt;float&gt;</c> -> <c>ReadOnlyMemorySingle</c>, <c>List&lt;byte&gt;</c> -> <c>ListByte</c>.
/// </summary>
[JsonSerializable(typeof(float[]))]
Comment thread
paulmedynski marked this conversation as resolved.
[JsonSerializable(typeof(ReadOnlyMemory<float>))]
[JsonSerializable(typeof(List<byte>))]
internal sealed partial class SqlClientJsonSerializerContext : JsonSerializerContext
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,7 @@ internal static object CoerceValue(object value, MetaType destinationType, out b
{
try
{
value = ((ISqlVector)new SqlVector<float>(JsonSerializer.Deserialize<float[]>((string)value))).VectorPayload;
value = ((ISqlVector)new SqlVector<float>(JsonSerializer.Deserialize((string)value, SqlClientJsonSerializerContext.Default.SingleArray))).VectorPayload;
}
catch (Exception ex) when (ex is ArgumentNullException || ex is JsonException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override byte[] MakeRequest(string url)

using (Stream stream = s_client.GetStreamAsync(url).ConfigureAwait(false).GetAwaiter().GetResult())
{
return JsonSerializer.Deserialize<List<byte>>(stream)?.ToArray();
return JsonSerializer.Deserialize(stream, SqlClientJsonSerializerContext.Default.ListByte)?.ToArray();
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ internal string GetString()
{
return SQLMessage.NullString();
}
return JsonSerializer.Serialize(Memory);
// GetTypeFieldsOrThrow guarantees T is float.
return JsonSerializer.Serialize((ReadOnlyMemory<float>)(object)Memory, SqlClientJsonSerializerContext.Default.ReadOnlyMemorySingle);
Comment thread
charlesroddie marked this conversation as resolved.
}

#endregion
Expand Down
Loading