Configure MongoDB serializers with support for (de)serializing properties with type Type
This commit is contained in:
parent
8da68c11c9
commit
efec65e819
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Elsa.Serialization.Converters;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
@ -10,11 +11,17 @@ namespace Elsa.Persistence.MongoDb.Serializers
|
|||
public class JObjectSerializer : IBsonSerializer<JObject>
|
||||
{
|
||||
public static JObjectSerializer Instance { get; } = new();
|
||||
private readonly JsonSerializerSettings _serializerSettings;
|
||||
|
||||
private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
|
||||
public JObjectSerializer()
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
_serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
|
||||
_serializerSettings.Converters.Add(new TypeJsonConverter());
|
||||
}
|
||||
|
||||
public Type ValueType => typeof(JObject);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Elsa.Serialization.Converters;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using NodaTime;
|
||||
|
|
@ -9,13 +10,19 @@ namespace Elsa.Persistence.MongoDb.Serializers
|
|||
public class ObjectSerializer : IBsonSerializer<object>
|
||||
{
|
||||
public static ObjectSerializer Instance { get; } = new();
|
||||
private readonly JsonSerializerSettings _serializerSettings;
|
||||
|
||||
private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
|
||||
public ObjectSerializer()
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
_serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
|
||||
_serializerSettings.Converters.Add(new TypeJsonConverter());
|
||||
}
|
||||
|
||||
public Type ValueType => typeof(object);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using Elsa.Models;
|
||||
using Elsa.Serialization.Converters;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using NodaTime;
|
||||
|
|
@ -10,14 +11,20 @@ namespace Elsa.Persistence.MongoDb.Serializers
|
|||
public class VariablesSerializer : IBsonSerializer<Variables>
|
||||
{
|
||||
public static VariablesSerializer Instance { get; } = new();
|
||||
private readonly JsonSerializerSettings _serializerSettings;
|
||||
|
||||
private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
|
||||
public VariablesSerializer()
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
|
||||
_serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
|
||||
_serializerSettings.Converters.Add(new TypeJsonConverter());
|
||||
}
|
||||
|
||||
public Type ValueType => typeof(Variables);
|
||||
|
||||
public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value) => Serialize(context, args, (Variables) value);
|
||||
|
|
|
|||
Loading…
Reference in a new issue