title: Incorrect serialization in C# using JSON.NET
body: <p>I am attempting to take an object structured like so</p>
  
  <pre><code>public class Item
  {
     public Guid SourceTypeID {get;set;}
     public Guid BrokerID {get;set;}
     public double Latitude {get;set;}
     public double Longitude {get;set;}
     public DateTime TimeStamp {get;set;}
     public object Payload {get;set;}
  }
  </code></pre>
  
  <p>and serialize it with JSON.NET using a call like:</p>
  
  <pre><code>Item expected = new Item()
  {
     SourceTypeID = Guid.NewGuid(),
     BrokerID = Guid.NewGuid(),
     Latitude = 33.657145,
     Longitude = -117.766684,
     TimeStamp = DateTime.Now,
     Payload = new byte[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
  };
  string jsonString = JsonConvert.SerializeObject(expected);
  </code></pre>
  
  <p>The payload member of the Item object will potentially hold any one primitive of a list of C# primitives (plus a few others like Guid), or an array of those types (as in the example, a byte array), or a "flat" object composed of any of those previously listed "primitives" (dynamically created).</p>
  
  <p>When I perform the SerializeObject() call, the string that is produced contains:</p>
  
  <pre><code>{"Payload":"AAECAwQFBgcICQ==","SourceTypeID":"d8220a4b-75b1-4b7a-8112-b7bdae956a45",
   "BrokerID":"951663c4-924e-4c86-a57a-7ed737501dbd",
   "TimeStamp":"\/Date(1328202421559-0600)\/",
   "Latitude":33.657145,"Longitude":-117.766684}
  </code></pre>
  
  <p>However when I make the deserializing call the item that is produced is partially incorrect</p>
  
  <pre><code>Item actual = JsonConvert.DeserializeObject&lt;Item&gt;(jsonString);
  
  actual.SourceTypeID : {00000000-0000-0000-0000-000000000000}
  actual.BrokerID : {951663c4-924e-4c86-a57a-7ed737501dbd}
  actual.Latitude : 33.657145;
  actual.Longitude : -117.766684;
  actual.TimeStamp : {2/2/2012 11:07:01 AM}
  actual.Payload : null
  </code></pre>
  
  <p>The SourceTypeID member (Guid), and the Payload member (object, holding a byte[]), are both incorrect. The serialized string seems to hold the right identity for the guid, but not for the byte array.</p>
  
  <p>I see that an alternate signatureof SerializeObject is</p>
  
  <pre><code>SerializeObject(object value, params JsonConverter[] converters);
  </code></pre>
  
  <p>Is this the correct way to inform the de/serialization engine about types that it apparently handles wrong? Since I am working with a limited set of "primitives" at the core of my object, if I could create a set of converters for each of those types, would that solve my problem? </p>
  
  <p>I want to avoid reinventing the wheel if possible, as it seems that this would be a problem that has already been handled gracefully, and I'd like to leverage something like that if available.</p>