diff --git a/src/Core/Models/Mail/IMailQueueMessage.cs b/src/Core/Models/Mail/IMailQueueMessage.cs index c9d70bc947..89899c0e8a 100644 --- a/src/Core/Models/Mail/IMailQueueMessage.cs +++ b/src/Core/Models/Mail/IMailQueueMessage.cs @@ -9,6 +9,6 @@ namespace Bit.Core.Models.Mail IEnumerable BccEmails { get; set; } string Category { get; set; } string TemplateName { get; set; } - object Model { get; set; } + dynamic Model { get; set; } } } diff --git a/src/Core/Models/Mail/MailQueueMessage.cs b/src/Core/Models/Mail/MailQueueMessage.cs index 2606853eb8..2fdc56750d 100644 --- a/src/Core/Models/Mail/MailQueueMessage.cs +++ b/src/Core/Models/Mail/MailQueueMessage.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using Newtonsoft.Json; +using Bit.Core.Utilities; namespace Bit.Core.Models.Mail { @@ -9,11 +11,12 @@ namespace Bit.Core.Models.Mail public IEnumerable BccEmails { get; set; } public string Category { get; set; } public string TemplateName { get; set; } - public object Model { get; set; } + [JsonConverter(typeof(ExpandoObjectJsonConverter))] + public dynamic Model { get; set; } public MailQueueMessage() { } - public MailQueueMessage(MailMessage message, string templateName, object model) + public MailQueueMessage(MailMessage message, string templateName, dynamic model) { Subject = message.Subject; ToEmails = message.ToEmails; diff --git a/src/Core/Utilities/ExpandoObjectJsonConverter.cs b/src/Core/Utilities/ExpandoObjectJsonConverter.cs new file mode 100644 index 0000000000..78a1ce87bc --- /dev/null +++ b/src/Core/Utilities/ExpandoObjectJsonConverter.cs @@ -0,0 +1,19 @@ +using System; +using System.Dynamic; +using Newtonsoft.Json; + +namespace Bit.Core.Utilities +{ + public class ExpandoObjectJsonConverter : JsonConverter + { + public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return serializer.Deserialize(reader); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); + } +}