postmark-dotnet
postmark-dotnet copied to clipboard
[4.8.0] Serialization for TemplateModel of TemplatedPostmarkMessage doesn't seem to work with Dictionaries anymore
In the following screenshots "TemplateModel" is a Dictionary<string,object>
With previous Versions (Tested with 4.7.12)
Correctly converted by "JsonContent" in the "PostmarkClientBase.cs" class
With 4.8.0 every value of the dictionary gets converted to an array:
Hey @mvpindev, I try to reproduce the issue but I can't get the TemplateModel values to get serialised as arrays, could you provide a small code snippet?
I tried
var t1 = new Dictionary<string, object>
{
{ "tenant", new { name = "Name1", logoUrl = "http://test1" } }
};
var t2 = new Dictionary<string, object>
{
{ "tenant", new Dictionary<string, object> { { "name", "Name1" }, { "logoUrl", "http://test1" } } }
};
and I get below in both cases
"TemplateModel": {
"tenant": {
"name": "Name1",
"logoUrl": "http://test1"
}
},
I'll try to create one asap
Hey @MariuszTrybus,
i was able to pinpoint what actually is/was wrong. My assumption of it being a dictionary of type Dictionary<string,object> was wrong.
Currently our code works similar to the following:
- Microservice_1 creates a "TemplateModel" just like you did in your "t2"- Example
- Microservice_1 sends a request including the Templatemodel to Microservice_2
- Microservice_2 deserializes the Body with Newtonsoft.Json
Which converts the templateModel from the RequestBody to the following:
var templateModel = new Dictionary<string, object>
{
{ "tenant", new Dictionary<string, Newtonsoft.Json.Linq.JToken> { { "name", "Name1" }, { "logoUrl", "http://test1" } } }
};
So i makes sense why it worked before in 4.7.12 where postmark-dotnet still used Newtonsoft internally.
I guess this can be closed, im sorry for the confusion
Thank you for creating the ticket and sharing your findings. It's an edge case but it may help others in the future. I am sorry for any inconvenience caused by the change.