title: how to not return null when a Data member field is not set in the data contract
body: <p>I'm having a strange problem with my <code>WCF</code> service that returns data in <code>JSON</code> format.
  I want to return information about a "Customer" based on the request sent by client. </p>
  
  <p>Client can request what fields of information about a customer they need and the service needs to send only that information about the customer.</p>
  
  <p>For Example: If client asks for a list of customers and says they want firstname, lastname, city
  of each customer then server should send a json response with each field name and corresponding value</p>
  
  <p>Something like... </p>
  
  <pre><code>[
    {"firstname":"john","lastname":"Goodman","city" :"NY"},
    {"firstname":"brad","lastname":"newman","city" :"LA"}
  ]
  </code></pre>
  
  <p>if client asks for list of customers with ID and city fields only then the response should look like this</p>
  
  <pre><code>[
    {"id" :"1234","city" :"NY"},
    {"id":"1235","city" :"LA"}
  ]
  </code></pre>
  
  <p>My initial design was to implement a "Customer" class and then have each possible "field"
  as a field of this class. Then inside my service method, I was getting the list of fields specified by the client and instantiating customer objects with only those properties set.</p>
  
  <p>My operation contract looks like this</p>
  
  <pre><code>[OperationContract]
  [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "Customers?fields={value}")]
  List&lt;Customer&gt; GetCustomers(string value);
  </code></pre>
  
  <p>But the problem is when I decorate the class with "DataContract" and each Field as "DataMember"....if some properties are not set, they still get deserialized as NULL when sent to client. I dont want this to happen.</p>
  
  <p>Also, the list of possible fields a customer is very long and so the class became very large. I would rather store these fields as an enum collection in my service rather than fields of a class.</p>
  
  <p>I then thought of having my Operation return a <code>IDictionary&lt;string,object&gt;</code> and then add each field and value iteratively to this collection. That didn't work because, when a dictionary is serialized it shows <code>{"Key:dfas", "Value:34"</code>} etc etc. not what i want</p>
  
  <p>So I'm kinda stuck. What's the best way to solve this problem? </p>
  
  <p>Can I mark my <code>[DataContract]</code> such a way that if <code>[DataMember]</code> properties are not set i.e, null then they shouldn't be serialized and send to client at all?</p>