Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mvpindev opened this issue Mar 4, 2024 · 4 comments

Comments

@mvpindev
Copy link

mvpindev commented Mar 4, 2024

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

@MariuszTrybus
Copy link
Contributor

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

@mvpindev
Copy link
Author

mvpindev commented Mar 5, 2024

I'll try to create one asap

@mvpindev
Copy link
Author

mvpindev commented Mar 5, 2024

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

@MariuszTrybus
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants