Expose a JsonSerializerOptions setting in the prompts APIs (#279)
* Expose a JsonSerializerOptions setting in the prompts APIs * Change namespace for workaround converter.
This commit is contained in:
parent
a896fa8055
commit
ce4e6586d2
1 changed files with 54 additions and 19 deletions
|
|
@ -1,15 +1,19 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
// NOTE:
|
||||
// This is a temporary workaround for lack of System.Text.Json's JsonStringEnumConverter<T>
|
||||
// This is a workaround for lack of System.Text.Json's JsonStringEnumConverter<T>
|
||||
// 9.x support for JsonStringEnumMemberNameAttribute. Once all builds use the System.Text.Json 9.x
|
||||
// version, this whole file can be removed.
|
||||
// version, this whole file can be removed. Note that the type is public so that external source
|
||||
// generators can use it, so removing it is a potential breaking change.
|
||||
|
||||
namespace System.Text.Json.Serialization;
|
||||
namespace ModelContextProtocol.Utils.Json;
|
||||
|
||||
/// <summary>
|
||||
/// A JSON converter for enums that allows customizing the serialized string value of enum members
|
||||
|
|
@ -21,7 +25,8 @@ namespace System.Text.Json.Serialization;
|
|||
/// 9.x support for custom enum member naming. It will be replaced by the built-in functionality
|
||||
/// once .NET 9 is fully adopted.
|
||||
/// </remarks>
|
||||
internal sealed class CustomizableJsonStringEnumConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TEnum> :
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public sealed class CustomizableJsonStringEnumConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TEnum> :
|
||||
JsonStringEnumConverter<TEnum> where TEnum : struct, Enum
|
||||
{
|
||||
#if !NET9_0_OR_GREATER
|
||||
|
|
|
|||
Loading…
Reference in a new issue