phatboyg/MassTransit — pull request #108 by rikbosch (2014-03-06 10:39:26+00:00)
Title: Json serializer does not serialize a string to a string when given a DateTime string

The Newtonsoft Json does some weird things when given a string property containing a "possible" DateTime.

for example, given the message below

```c#
_message = new TestMessage
{
Name = "Joe",
Details = new List
{
new TestMessageDetail {Item = "A", Value = 27.5d},
new TestMessageDetail {Item = "B", Value = 13.5d},
},
DateTimeProperty = new DateTime(2014,03,05,01,53,04,193),
DateTimeStringProperty = "2014-03-05T01:53:04.193",
Dictionary = new Dictionary()
{
{"string-datetime-property","2014-03-05T01:53:04.193"}
}
};
```

Default, the newtonsoft serializer deserializes the DateTimeStringProperty into a DateTime, when it is actually a string:

```c#
using (var jsonReader = new JTokenReader(result.Message as JToken))
{
var message = (TestMessage)_serializer.Deserialize(jsonReader, typeof(TestMessage));

// DateTimes are properly serialized / deserialized
// however, string properties containing a date-string are somehow
// converted to a Datetime somewhere in deserialization
// fixed by adding DateParseHandling = DateParseHandling.None to serializer settings

// works OK using default settings
message.DateTimeProperty.ShouldEqual(new DateTime(2014, 03, 05, 01, 53, 04, 193),"Round ripping DateTimeProperty failed");

// NOT ok, result is "03/05/2014 01:53:04"
message.DateTimeStringProperty.ShouldEqual("2014-03-05T01:53:04.193", "Roundtripping DateTimeStringProperty failed");

// NOT ok, result is "03/05/2014 01:53:04"
message.Dictionary["string-datetime-property"].ShouldEqual("2014-03-05T01:53:04.193", "Roundtripping datetimestring in dictionary failed");

}
```

this behavior can be changed by adding `DateParseHandling = DateParseHandling.None` to the serializer settings.