MichaelT
MichaelT

Reputation: 7934

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

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

Upvotes: 3

Views: 2836

Answers (1)

Sando
Sando

Reputation: 667

You can use:

[JsonIgnore]
[XmlIgnore]

These will hide your property from both kinds of serialization. I have always tried to mix both in a single class but JSonIgnoreAtrribute is a sealed class and does not leave us with a seamless integration option.

So the straight forward way is to add both attributes on your ignorable property.

Upvotes: 7

Related Questions