title: How can I make DataContractJsonSerializer serialize an object as a string?
body: <p>I have a struct in C# that wraps a guid.  I'm using DataContractJsonSerializer to serialize an object containing an instance of that class.  When I was using a guid directly, it was serialized as a plain string, but now it's serialized as a name/value pair.  Here's an NUnit test and supporting code that demonstrates the problem:</p>
  
  <pre><code>    private static string ToJson&lt;T&gt;(T data)
      {
          DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof (T));
  
          using (MemoryStream ms = new MemoryStream())
          {
              serializer.WriteObject(ms, data);
              return Encoding.Default.GetString(ms.ToArray());
          }
      }
  
      [Serializable]
      private class ID
      {
          private Guid _value;
  
          public static explicit operator ID(Guid id)
          {
              return new ID { _value = id };
          }
  
          public static explicit operator Guid(ID id)
          {
              return id._value;
          }
      }
  
      [Test]
      public void IDShouldSerializeLikeGuid()
      {
          Guid guid = Guid.NewGuid();
          ID id = (ID) guid;
          Assert.That(ToJson(id), Is.EqualTo(ToJson(guid)));
      }
  </code></pre>
  
  <p>And the test runner output:</p>
  
  <pre><code>NUnit.Framework.AssertionException:   Expected string length 38 but was 49. Strings differ at index 0.
    Expected: ""7511fb9f-3515-4e95-9a04-06580753527d""
    But was:  "{"_value":"7511fb9f-3515-4e95-9a04-06580753527d"}"
    -----------^
  </code></pre>
  
  <p>How do I serialize my struct as a plain string and make my test pass?</p>