add default serializer for AppVersion

This commit is contained in:
2024-06-27 09:44:12 +02:00
parent a68ccb5daf
commit 932f9eff06
2 changed files with 8 additions and 2 deletions

View File

@@ -1,7 +1,9 @@
using Newtonsoft.Json;
using Pilz.Updating.Json;
namespace Pilz.Updating;
[JsonConverter(typeof(AppVersionStringJsonConverter))]
public class AppVersion(Version version, int build, Channels channel)
{
// P r o p e r t i e s

View File

@@ -3,8 +3,12 @@ using Newtonsoft.Json.Linq;
namespace Pilz.Updating.Json;
public class AppVersionStringJsonConverter : JsonConverter
public class AppVersionStringJsonConverter(bool serializeAsObject) : JsonConverter
{
public AppVersionStringJsonConverter() : this(false)
{
}
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
@@ -19,7 +23,7 @@ public class AppVersionStringJsonConverter : JsonConverter
return;
}
if (value is not AppVersion appVersion)
if (serializeAsObject || value is not AppVersion appVersion)
writer.WriteValue(value);
else
writer.WriteValue(appVersion.ToString());