title: How to Ignore Null values while serializing OData response
body: <p>I've a requirement to omit the null valued fields from the response altogether.
  I can do this by modifying the JsonFormatter Serialization Setting for a normal webapi response.</p>
  
  <pre><code>config.Formatters.JsonFormatter.SerializationSettings
        .NullValueHandling = NullValueHandling.Ignore;
  </code></pre>
  
  <p>But that does not seem to work once i switch to <code>OData</code>.</p>
  
  <p>Here are my files:
  WebApi.config:</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      var builder = new ODataConventionModelBuilder();
      var workerEntitySet = builder.EntitySet&lt;Item&gt;("Values");
      config.Routes.MapODataRoute("Default", "api", builder.GetEdmModel());
  }
  </code></pre>
  
  <p>Item Model:</p>
  
  <pre><code>public class Item
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string OptionalField { get; set; }
  }
  </code></pre>
  
  <p>ValuesController:</p>
  
  <pre><code>public class ValuesController : EntitySetController&lt;Item, int&gt;
  {
      public static List&lt;Item&gt; items = new List&lt;Item&gt;() 
      {
          new Item { Id = 1, Name = "name1", OptionalField = "Value Present" }, 
          new Item { Id = 3, Name = "name2" } 
      };
      [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
      public override IQueryable&lt;Item&gt; Get()
      {
          return items.AsQueryable();
      }
      [Queryable]
      protected override Item GetEntityByKey(int  id)
      {
          return items.Single(i =&gt; i.Id == id);
      }
  }
  </code></pre>
  
  <p>Here is the response I get for GET: api/Values. </p>
  
  <pre><code>{
   "odata.metadata":"http://localhost:28776/api/$metadata#Values",
   "value":[
     {
       "Id":1,
       "Name":"name1",
       "OptionalField":"Value Present"
     },
     {
       "Id":3,
       "Name":"name2",
       "OptionalField":null
     }
    ]
  }
  </code></pre>
  
  <p>But I do not need the elements with null values present in the response - in the response below, I need the "OptionalField" not to be present in the second item (As its value is null). I need to achieve it in my response, I do not want the users to query for non-null values only.</p>