|
|
@@ -1,10 +1,7 @@
|
|
|
-using com.sun.jmx.mbeanserver;
|
|
|
-using Comal.Classes;
|
|
|
+using Comal.Classes;
|
|
|
using Expressive;
|
|
|
using InABox.Core;
|
|
|
using InABox.Database;
|
|
|
-using Newtonsoft.Json;
|
|
|
-using Newtonsoft.Json.Serialization;
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
@@ -12,6 +9,9 @@ using System.Diagnostics.CodeAnalysis;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Text.Json.Serialization;
|
|
|
+using System.Text.Json.Serialization.Metadata;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace PRS.Shared.Events;
|
|
|
@@ -50,6 +50,9 @@ public class EventData<T, TDataModel> : IEventData
|
|
|
Actions = new List<IEventAction<T>>();
|
|
|
}
|
|
|
|
|
|
+ [JsonConstructor]
|
|
|
+ private EventData(): this(default) { }
|
|
|
+
|
|
|
public Notification GenerateNotification(TDataModel model) => Event.GenerateNotification(model);
|
|
|
}
|
|
|
|
|
|
@@ -57,31 +60,28 @@ public static class EventUtils
|
|
|
{
|
|
|
#region Serialisation
|
|
|
|
|
|
- private class WritablePropertiesOnlyResolver : DefaultContractResolver
|
|
|
- {
|
|
|
- protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
|
|
- {
|
|
|
- IList<JsonProperty> props = base.CreateProperties(type, memberSerialization);
|
|
|
- return props.Where(p => p.Writable).ToList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static JsonSerializerSettings SerializationSettings()
|
|
|
+ private static JsonSerializerOptions SerializationSettings()
|
|
|
{
|
|
|
var settings = Serialization.CreateSerializerSettings();
|
|
|
- settings.TypeNameHandling = TypeNameHandling.Auto;
|
|
|
- settings.ContractResolver = new WritablePropertiesOnlyResolver();
|
|
|
+ settings.TypeInfoResolver = new DefaultJsonTypeInfoResolver
|
|
|
+ {
|
|
|
+ Modifiers =
|
|
|
+ {
|
|
|
+ Serialization.WritablePropertiesOnly
|
|
|
+ }
|
|
|
+ };
|
|
|
+ settings.Converters.Add(new PolymorphicConverter());
|
|
|
return settings;
|
|
|
}
|
|
|
|
|
|
public static string Serialize(IEventData data)
|
|
|
{
|
|
|
- return JsonConvert.SerializeObject(data, typeof(IEventData), SerializationSettings());
|
|
|
+ return JsonSerializer.Serialize(data, typeof(IEventData), SerializationSettings());
|
|
|
}
|
|
|
|
|
|
public static IEventData Deserialize(string json)
|
|
|
{
|
|
|
- return JsonConvert.DeserializeObject<IEventData>(json, SerializationSettings())!;
|
|
|
+ return JsonSerializer.Deserialize<IEventData>(json, SerializationSettings())!;
|
|
|
}
|
|
|
|
|
|
#endregion
|