Fields filtering in ASP .NET Web API

One thought on “Fields filtering in ASP .NET Web API”

  1. Shweta,

    Nice solution. I was looking to make it a bit more generic and a couple of small tweaks would keep the duplication to a minimum. You are already testing to make sure that the base type is BaseEntity so you are safe to assume that if you get into the serialization code that the object will have a SerializeableProperties collection. As a result, you can declare the ShouldSerializeContractResolver and use a dynamic when getting / casting the instance. It won’t let me post the entire snippet so here is the class declaration:

    public class ShouldSerializeContractResolver : DefaultContractResolver

    Usage:

    return Json(product, new Newtonsoft.Json.JsonSerializerSettings()
    {
    ContractResolver = new ShouldSerializeContractResolver()
    });

    Thanks for the solution.

    Jim

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s