i want to change the json property name dynamically and serialize the object.
here is my json for two different entities
For customer
{
"userName": "66666",
"password": "test1234",
"customersList": [
{
"address": "Test Stree2",
"customerNumber": "US01-000281",
"city": ""
}
]
}
For contact
{
"userName": "66666",
"password": "test1234",
"contactList": [
{
"address": "Test stree1",
"contactNumber": "US01-000281",
"city": ""
}
]
}
and the model that is holding this data is as follows
public class URequest<T>
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string userName { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string password { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public IList<T> requestList { get; set; }
}
in above code requestList could contain list of contacts or customer but while sending i want to change the requestList json property name to respective entity name i.e. for customer it will be customerList and for contact it will be contactList after serializing.