Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack.Text and ISODate("")

Why ServiceStack.Text DeserializeFromString cant convert ISODate formats.

For example, i have json string like

{ "Count" : 4, "Type" : 1, "Date" : ISODate("2013-04-12T00:00:00Z") }

and class

public class TestClass
{
    public int Count { get; set; }
    public int Type { get; set; }
    public DateTime Date { get; set; }
}

and when i try to deserialize from string

JsonSerializer.DeserializeFromString<TestClass>(json);

give me output like enter image description here

like image 577
Novkovski Stevo Bato Avatar asked Apr 13 '13 21:04

Novkovski Stevo Bato


2 Answers

ServiceStack.Text understands ISO8601, too.

You can configure it as the default behaviour with:

JsConfig.DateHandler = JsonDateHandler.ISO8601;

See this answer for more information.

like image 56
Christian Specht Avatar answered Oct 01 '22 17:10

Christian Specht


JSON expects the date format like this

"LastRequestTime":"\/Date(928129800000+0530)\/"

So change you date value in Json string and then try. it will deserialized that property properly.

like image 35
Sachin Avatar answered Oct 01 '22 17:10

Sachin