My Servicestack Instance is configured to render JSON dates as ISO8601 in Global.asax
JsConfig.DateHandler = DateHandler.ISO8601
I have a POCO that uses a nullable DateTime:
public class WindowsUser
{
public DateTime? CreationDate { get; set; }
}
This POCO is used in an endpoint that lists all instances of that type, and in an AutoQuery Data endpoint that allows for searching:
[Route("/users/windows", "GET", Summary = "Lists all users from Active Directory")]
public class GetWindowsUsers : IReturn<List<WindowsUser>>
{
}
[Route("/users/windows/search", "GET", Summary = "Search users")]
public class SearchWindowsUsers : QueryData<WindowsUser>
{
}
The AutoQuery endpoint is the point that is using an AutoQuery ServiceSource to provide queryable results:
[Route("/users/windows/search", "GET", Summary = "Search users")]
public class SearchWindowsUsers : QueryData<WindowsUser>
{
}
The direct endpoint is the source of the above endpoint, also exposed as a separate endpoint:
[Route("/users/windows", "GET", Summary = "Lists all users from Active Directory")]
public class GetWindowsUsers : IReturn<List<WindowsUser>>
{
}
I’ve skipped the service implementation code (i.e
public List<WindowsUser> Any(GetWindowsUsers request)
{
' Get data
}
```
but the `creationDate` values above are from the JSON response. When `creationDate` is retreived outside AutoQuery, I get a 8601 Date minus the timezone.
```
"creationDate": "2004-09-23T20:41:52.0000000"
```
When I first created this thread, I thought I was getting different responses from the AutoQuery result set, but it's actually only when the AutoQuery result set is returned from cached data. i.e. the first time `/users/windows/search` is invoked, `creationDate` is identical to the source service endpoint. When `/users/windows/search` is invoked a second time, and the data is retrieved from Redis (my cache), the timezone is included:
```
"creationDate": "2004-09-23T20:41:52.0000000-05:00"
```
Does that help clarify things?
I should add that the cached results of /users/windows do not include the time zone in the creationDate– this just happens with the cached AutoQuery results.
Dates are serialized as UTC but deserialized back into LocalTime by default as the Kind is not preserved during Serialization. You can try use JsConfig.SkipDateTimeConversion = true to skip the implied conversion.