Skip to content

Feature Request: Custom serializer option to handle Dynamic Template Data serialization #985

@shervinw

Description

@shervinw

example:

var msg = new SendGridMessage();
var serializerSettings = new Newtonsoft.Json.JsonSerializerSettings
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };
msg.SetTemplateData(dynamicTemplateData, serializerSettings);

Current options are far too restrictive, I can only see that decorating properties with JsonProperty has any type of effect.

Also, I'm sure this test is simply testing Newtonsofts lib.

Activity

eshanholtz

eshanholtz commented on Mar 24, 2020

@eshanholtz
Contributor

Pull requests to add this feature are welcome and will be reviewed based on priority, but Twilio SendGrid is not actively building new functionality for the library.

shervinw

shervinw commented on Mar 26, 2020

@shervinw
Author

More than happy to do so! Following all guidelines!

Looking at open pull requests, may I ask the time it may take to merge this functionality?

tunminster

tunminster commented on Sep 28, 2020

@tunminster

@shervinw @eshanholtz Not sure if the pull request is already there? we have bumped into this with .net 5. #1050

childish-sambino

childish-sambino commented on Sep 29, 2020

@childish-sambino
Contributor

No PRs yet, but they are welcome!

fabio-s-franco

fabio-s-franco commented on Aug 18, 2021

@fabio-s-franco

Over an year now and still no support to native .net serializer...

Aren't these client libraries supposed to supported by Twilio? There is even a PR just sitting there and really no real effort to make it happen. 3 days for now .net 2.1 end of support is there and this will not have happened.

vdurante

vdurante commented on Nov 26, 2021

@vdurante

+1

kshyju

kshyju commented on Jan 20, 2022

@kshyju

but Twilio SendGrid is not actively building new functionality for the library.

@eshanholtz Does this mean that there will not be a version of this library with System.Text.Json support? Currently some of the types has a strong dependency on JSON.NET.

Asking it here because1050 was closed as it was marked as dupe of this. Thanks!

Sharparam

Sharparam commented on Feb 28, 2022

@Sharparam

Would be good with some updates on this. We're hitting this as an issue as well when replacing Newtonsoft.Json with System.Text.Json.

Most other libraries have a way to set a custom serializer which lets us configure them properly, but this library does not.

Is development on this project stopped which means Twilio is no longer supplying an official C#/.NET SDK?

Edit: As an ugly workaround, since we only seem to have issues with TemplateData.

var templateDataJson = JsonSerializer.Serialize(templateData);
var njTemplateData = Newtonsoft.Json.JsonConvert.DeserializeObject<object?>(templateDataJson);
sendGridMessage.SetTemplateData(njTemplateData);

Basically, we take the current template data (deserialized with STJ, so it has JsonElement and friends), serialize it to plain JSON, then deserialize that using Newtonsoft.Json to get the proper dynamic JSON types (JToken and friends).

fabio-s-franco

fabio-s-franco commented on Mar 3, 2022

@fabio-s-franco

Had to employ the same ugly and ineffective solution @Sharparam .

It's funny how they put it in the home page as they want this library to be community driven. But someone comes, makes all the effort (a lot of effort), keeps it updated, follow the guidelines and after almost an entire year and the pull request is still there:

#1110

Don't think there is enough respect to the effort being made there. And this will never be community driven when there is a gatekeeper acting as a bottleneck for community driven work.

Jericho

Jericho commented on Apr 25, 2022

@Jericho

If anybody is still waiting for a solution to customize how you dynamic template data is serialized, I suggest you have a look at StrongGrid which is an alternative to SendGrid's client (disclaimer: I'm the author). StrongGrid allows you to specify your own serialization options, including the naming policy.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Jericho@kshyju@Sharparam@tunminster@vdurante

        Issue actions

          Feature Request: Custom serializer option to handle Dynamic Template Data serialization · Issue #985 · sendgrid/sendgrid-csharp