rest - How to rename Request/Response object properties in ASP.Net MVC Web API? -


could me please minimize response of web api route.

public class product {     public string uniqueid {get;set;}     public string title {get;set;}     ... }  public class productscontroller : apicontroller {     public ienumerable<product> getallproducts()     {         return repository.getall();     }     // .... } 

the response contains full names of entity properties:

[{     uniqueid: 123,     title: 'book 1' },...] 

i minimize traffic using short aliases dto properties , see this:

[{     u: 123,     t: 'book 1' },...] 

i'm wondering if special attributes used rename properties in request/response. btw i'm talking requests because have same issue post requests.

try applying following attribute on dto's properties:

[jsonproperty(propertyname = "u")] public string uniqueid {get; set;} 

in way, json.net know name use when serializing or deserializing dtos.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -