Fix launcher not showing mods
Convert `Version` and `SptVersion` to strings when serializing JSON for AbstractModMetadata
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Range = SemanticVersioning.Range;
|
using System.Text.Json.Serialization;
|
||||||
|
using SPTarkov.Server.Core.Utils.Json.Converters;
|
||||||
|
using Range = SemanticVersioning.Range;
|
||||||
using Version = SemanticVersioning.Version;
|
using Version = SemanticVersioning.Version;
|
||||||
|
|
||||||
namespace SPTarkov.Server.Core.Models.Spt.Mod;
|
namespace SPTarkov.Server.Core.Models.Spt.Mod;
|
||||||
@@ -40,6 +42,7 @@ public abstract record AbstractModMetadata
|
|||||||
/// <br/>
|
/// <br/>
|
||||||
/// Version = new Version("1.0.0.0"); is not
|
/// Version = new Version("1.0.0.0"); is not
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ToStringJsonConverter<Version>))]
|
||||||
public abstract Version Version { get; init; }
|
public abstract Version Version { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -49,6 +52,7 @@ public abstract record AbstractModMetadata
|
|||||||
/// <br/>
|
/// <br/>
|
||||||
/// Version = new Version("4.0.0.0"); is not
|
/// Version = new Version("4.0.0.0"); is not
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ToStringJsonConverter<Range>))]
|
||||||
public abstract Range SptVersion { get; init; }
|
public abstract Range SptVersion { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user