mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
tcloud compatibility, dotnet bug fixes
This commit is contained in:
29
enterprise/SingleOrArrayConverter.cs
Normal file
29
enterprise/SingleOrArrayConverter.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace TrainSearchWorker.Converters
|
||||
{
|
||||
public class SingleOrArrayConverter<T> : JsonConverter<List<T>>
|
||||
{
|
||||
public override List<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.StartArray)
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<T>>(ref reader, options) ?? new List<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Single element – wrap it in a list.
|
||||
T element = JsonSerializer.Deserialize<T>(ref reader, options);
|
||||
return new List<T> { element };
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, List<T> value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user