postmark-dotnet icon indicating copy to clipboard operation
postmark-dotnet copied to clipboard

[4.8.0] Serialization for TemplateModel of TemplatedPostmarkMessage doesn't seem to work with Dictionaries anymore

Open mvpindev opened this issue 11 months ago • 4 comments

In the following screenshots "TemplateModel" is a Dictionary<string,object>

With previous Versions (Tested with 4.7.12) image

Correctly converted by "JsonContent" in the "PostmarkClientBase.cs" class image

With 4.8.0 every value of the dictionary gets converted to an array: image

mvpindev avatar Mar 04 '24 14:03 mvpindev

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"
    }
  },

MariuszTrybus avatar Mar 04 '24 16:03 MariuszTrybus

I'll try to create one asap

mvpindev avatar Mar 05 '24 07:03 mvpindev

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:

  1. Microservice_1 creates a "TemplateModel" just like you did in your "t2"- Example
  2. Microservice_1 sends a request including the Templatemodel to Microservice_2
  3. 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

mvpindev avatar Mar 05 '24 11:03 mvpindev

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.

MariuszTrybus avatar Mar 05 '24 12:03 MariuszTrybus