I'm implementing a 3rd parties RestFul API. The majority of the Json properties in the request and response data is formatted with underscore characters instead of spaces and all lower case. For example
{
"message_id" : "QWERTY",
"other_reference" : 12345
}
I am not a fan of this format in my internal code, I would prefer my model to be the following.
public class data
{
string MessageId {get; set;}
int OtherReference {get; set;}
}
Is there an easy way to get the serialiser/de-serialiser to do the mapping for me (using System.Text.Json) ? I know I can use the attribute JsonPropertyName
to do it, but that means adding the attribute to all properties (there are a lot of them), although this method does allow me to use more meaningful names in my code (some of the names in the Json could be a little confusing to someone visiting the code at a later date if they don't have the subject knowledge)
Thanks