How to exclude some property from an object in ASP.NET WebApi

If I have an object that I am returning from WebApi, is it possible to mark one of the properties as hidden?

+4
source share
1 answer

You can use:

[JsonIgnore] [XmlIgnore] 

They will hide your property from both types of serialization. I always tried to mix both in one class, but JSonIgnoreAtrribute is a private class and does not leave us with the possibility of seamless integration.

So the direct way is to add both attributes to your ignorant property.

+8
source

All Articles