AutoQuery Data DateTime format differs from Source Service

Hello,

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>
    {        
    }

(and in Global.asax)

 Plugins.Add(new AutoQueryDataFeature {MaxLimit = 1000}
 .AddDataSource(ctx => ctx.ServiceSource<WindowsUser>(new GetWindowsUsers(), HostContext.Cache, TimeSpan.FromMinutes(5)))

The source of CreationDate is a UTC DateTime object.

When I view records through the AutoQuery endpoint, a time zone gets included:

"creationDate": "2004-09-23T20:41:52.0000000-05:00"

The direct endpoint does not include the time zone:

"creationDate": "2004-09-23T20:41:52.0000000"

Any reason this is the case?

I don’t know what the difference of what you mean by between “the AutoQuery endpoint” or “direct endpoint”, what is the actual JSON response?

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.

Ok, that works, but it is strange that I only saw the LocalTime deserialization when it was both from AutoQuery and cached.

Thanks!

It’s only ever deserialized when it’s deserialized from a distributed Cache, otherwise it’s only being serialized.