Control ASP.NET WebAPI JSON serialisation without access to source code -


i using asp.net webapi return object assembly can't change source code in.

i want remove 1 property response, cannot add [jsonignore] property because can't edit class returning.

is there way specify separate property ignore list?

there serialization happening automatically @ moment using ok() method:

return ok(myobject); 

you can create custom newtonsoft.json.serialization.icontractresolver conditionally serialize properties.

for more info on json.net's support in space, can take @ following link: http://james.newtonking.com/json/help/index.html?topic=html/contractresolver.htm

config.formatters.jsonformatter.serializersettings.contractresolver = new shouldserializecontractresolver();  public class shouldserializecontractresolver : system.net.formatting.jsoncontractresolver {     public new static readonly shouldserializecontractresolver instance = new shouldserializecontractresolver();      protected override jsonproperty createproperty(memberinfo member, memberserialization memberserialization)     {         jsonproperty property = base.createproperty(member, memberserialization);          if (property.declaringtype == typeof(employee) && property.propertyname == "manager")         {             property.shouldserialize =                 instance =>                 {                     employee e = (employee)instance;                     return e.manager != e;                 };         }          return property;     } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -