Fix MongoDb NodaTime deserialization issue
This commit is contained in:
parent
1ea227279c
commit
3282ac26c5
|
|
@ -14,7 +14,11 @@ namespace Elsa.Extensions
|
|||
public static T GetState<T>(this JObject state, string key, Func<T> defaultValue = null)
|
||||
{
|
||||
var item = state.GetValue(key, StringComparison.OrdinalIgnoreCase);
|
||||
return item != null && item.Type != JTokenType.Null ? item.ToObject<T>(Serializer) : defaultValue != null ? defaultValue() : default(T);
|
||||
|
||||
if (item == null || item.Type == JTokenType.Null)
|
||||
return defaultValue != null ? defaultValue() : default;
|
||||
|
||||
return item.ToObject<T>(Serializer);
|
||||
}
|
||||
|
||||
public static T GetState<T>(this JObject state, Type type, string key, Func<T> defaultValue = null)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Elsa.Serialization
|
||||
{
|
||||
public interface IWorkflowSerializerProvider
|
||||
{
|
||||
JsonSerializer CreateJsonSerializer();
|
||||
}
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Elsa.Serialization
|
||||
{
|
||||
public interface IWorkflowSerializerProvider
|
||||
{
|
||||
JsonSerializerSettings CreateJsonSerializerSettings();
|
||||
JsonSerializer CreateJsonSerializer();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,15 @@ namespace Elsa.Serialization
|
|||
{
|
||||
public class WorkflowSerializerProvider : IWorkflowSerializerProvider
|
||||
{
|
||||
public JsonSerializerSettings CreateJsonSerializerSettings()
|
||||
{
|
||||
return new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
}.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
}
|
||||
|
||||
public JsonSerializer CreateJsonSerializer()
|
||||
{
|
||||
var jsonSerializer = new JsonSerializer();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NodaTime;
|
||||
using NodaTime.Serialization.JsonNet;
|
||||
|
||||
namespace Elsa.Persistence.MongoDb.Serialization
|
||||
{
|
||||
|
|
@ -10,7 +13,9 @@ namespace Elsa.Persistence.MongoDb.Serialization
|
|||
public override JObject Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
||||
{
|
||||
var document = BsonDocumentSerializer.Instance.Deserialize(context);
|
||||
return JObject.Parse(document.ToString());
|
||||
var settings = new JsonSerializerSettings().ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
|
||||
return JsonConvert.DeserializeObject<JObject>(document.ToString(), settings);
|
||||
}
|
||||
|
||||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, JObject value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue