Custom serialization with Newtonsoft JSON

Viewed 171

Here's my issue : I have an object that will be serialized and send to SendGrid.

public class CustomFields
{
    [JsonProperty("e1_T")]
    public string? AdherentType { get; set; }     
}

As you can see, I need the property name to be "e1_T" in the Json. This way works fine but I need now to externalize the name of the JsonProperty to put it in a conf file that change betwen environement. I tried things like

public class CustomFields
{
    public string fieldName = "wololo";
    
    [JsonProperty(fieldName)]
    public string? AdherentType { get; set; }     
} 

But it won't do the trick.

Any Idea how to make this append ?

0 Answers
Related