b416d7109a
Convert `Version` and `SptVersion` to strings when serializing JSON for AbstractModMetadata
25 lines
691 B
C#
25 lines
691 B
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace SPTarkov.Server.Core.Utils.Json.Converters;
|
|
|
|
internal class ToStringJsonConverter<T> : JsonConverter<T>
|
|
{
|
|
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
throw new NotSupportedException($"Deserialization of {typeof(T).Name} from string is not supported.");
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
|
{
|
|
if (value == null)
|
|
{
|
|
writer.WriteNullValue();
|
|
}
|
|
else
|
|
{
|
|
writer.WriteStringValue(value.ToString());
|
|
}
|
|
}
|
|
}
|