title: DataMember Emit Default Value
body: <p>I have a .Net Web Service function that can accept one string.</p>
  
  <p>That function will then serialize that string to JSON, but I only want to serialize it if it's value is not "".</p>
  
  <p>I found these instructions:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/aa347792.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa347792.aspx</a></p>
  
  <pre><code>[DataContract]
  public class MyClass
  {
     [DataMember (EmitDefaultValue=false)]
     public string myValue = ""
  }
  </code></pre>
  
  <p>Unfortunatelly I can not hide the myValue from the serialization because "" is not the .Net default value for a string (how dumb is that!)</p>
  
  <p>One of two option ocurred</p>
  
  <ol>
  <li><p>On the web service have some kind of attribute that sets the "" to null</p></li>
  <li><p>Have some condition on the class</p></li>
  </ol>
  
  <p>I would prefer the 1st because it makes the code cleaner but an opinion would be great.</p>
  
  <p>Thanks</p>