title: Hide object property when null when returning to View
body: <p>Say i have a C# Class called Vehicle:</p>
  
  <pre><code>public class Vehicle {
      public int VehicleNumber {get;set;}
      public string SerialNumber {get;set;}
      public string Model {get;set;}
  }
  </code></pre>
  
  <p>Now this is a function in a webApi controller:</p>
  
  <pre><code>public string Get(){
      return new Vehicle {VehicleNumber = 1, Model = "Lexus car"}
  }
  </code></pre>
  
  <p>The Json object I would receive upon sending the get request would be:</p>
  
  <pre><code>{ "VehicleNumber" : 1, "SerialNumber" : null, "Model" = "Lexus Car"}
  </code></pre>
  
  <p>Is there a way to omit properties that are null from the end result? so that my final result would like so:</p>
  
  <pre><code>{ "VehicleNumber" : 1, "Model" = "Lexus Car"}
  </code></pre>
  
  <p>Edit: This question seemse to be very similar to another question that i have not encountered untill commented on this question.</p>
  
  <p>But it is not entirely identical. Is there any way that with Data Annotations i can prevent serialization of a property if the property is null?</p>