2
Hello, I’m making an integration with the Tray Comerce API and thought to generate a generic class with the response of lists. In all listings, the API implements the following return class:
public class Response<T>
{
[JsonProperty("paging")]
public ResponsePaging Paging { get; set; }
[JsonProperty("sort")]
public Dictionary<string, string> Sort { get; set; }
[JsonProperty("availableFilters")]
public List<string> AvailableFilters { get; set; }
[JsonProperty("appliedFilters")]
public List<string> AppliedFilters { get; set; }
[JsonProperty(????)]
public List<T> List { get; set; }
public class ResponsePaging
{
public int total { get; set; }
public int page { get; set; }
public int offset { get; set; }
public int limit { get; set; }
public int maxLimit { get; set; }
}
}
The problem is that for each API route that makes a listing, the result of that listing is set to a different name (e.g. {web_api}/orders
returns Orders, in {web_api}/products
returns Products, etc....)
How do I pass as parameter to the class which will be the name of the property that will be assigned to [JsonProperty(????)]
of property List<T> List
?
I did some research and it looks like you might be able to replace
DefaultContractResolver
and implement its own mechanism to provide Propertyname (in JSON). https://stackoverflow.com/a/26883987/194717– Tony
I did my Contractresolver, I just don’t know how to implement it. Do you have any example? , I’m hunting here but just think how to create it..
– LeandroLuk