Vote count:
0
Consider the following ServiceStack JsConfig:
JsConfig.EmitCamelCaseNames = false;
JsConfig.DateHandler = JsonDateHandler.ISO8601;
JsConfig.AlwaysUseUtc = true;
JsConfig.AssumeUtc = true;
And the following unit test:
[Test]
public void DateTimeTest()
{
var test = new TestDates
{
DT1 = new DateTime(2015, 1, 1, 0, 0, 1, DateTimeKind.Utc),
DT2 = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc),
};
var testSerialised = TypeSerializer.SerializeToString(test);
var testDeserialised = TypeSerializer.DeserializeFromString<TestDates>(testSerialised);
Assert.AreEqual(test.DT1, testDeserialised.DT1);
Assert.AreEqual(test.DT2, testDeserialised.DT2);
}
And the unit test output:
Where a datetime object has 0 hours/mins/seconds etc... it is serialized without the 00:00:00Z part which causes the de-serialization to attempt to convert datetime objects to my local time (GMT+2) and ignore the JsConfig.
My question is, any idea why this occurs? Using ServiceStack's JsonSerializer i do not get this issue, and the JsConfig is obeyed.
I am using ServiceStack 3.9.71.0 :)
asked 1 min ago
ServiceStack TypeSerializer ignoring JsConfig
Aucun commentaire:
Enregistrer un commentaire