add default serializer for AppVersion
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Pilz.Updating.Json;
|
||||||
|
|
||||||
namespace Pilz.Updating;
|
namespace Pilz.Updating;
|
||||||
|
|
||||||
|
[JsonConverter(typeof(AppVersionStringJsonConverter))]
|
||||||
public class AppVersion(Version version, int build, Channels channel)
|
public class AppVersion(Version version, int build, Channels channel)
|
||||||
{
|
{
|
||||||
// P r o p e r t i e s
|
// P r o p e r t i e s
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ using Newtonsoft.Json.Linq;
|
|||||||
|
|
||||||
namespace Pilz.Updating.Json;
|
namespace Pilz.Updating.Json;
|
||||||
|
|
||||||
public class AppVersionStringJsonConverter : JsonConverter
|
public class AppVersionStringJsonConverter(bool serializeAsObject) : JsonConverter
|
||||||
{
|
{
|
||||||
|
public AppVersionStringJsonConverter() : this(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the JSON representation of the object.
|
/// Writes the JSON representation of the object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,7 +23,7 @@ public class AppVersionStringJsonConverter : JsonConverter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is not AppVersion appVersion)
|
if (serializeAsObject || value is not AppVersion appVersion)
|
||||||
writer.WriteValue(value);
|
writer.WriteValue(value);
|
||||||
else
|
else
|
||||||
writer.WriteValue(appVersion.ToString());
|
writer.WriteValue(appVersion.ToString());
|
||||||
|
|||||||
Reference in New Issue
Block a user