DateTime conversion on blobbed data

ServiceStack version 8.3.0

We have an POCO with a list of objects. We store the POCO and the list gets serialized into a field with DateTime data stored in UTC.

For example:

class A {
  public string Location { get; set; }
  public DateTime Start { get; set; } // Stores fine, appears to deserialize on the client incorrectly
}

class B {
  public B() {
    AList = new List<A>();
  } 
  public string Code { get; set; }
  public DateTime WhenDispatched { get; set; } // No issues with this on the client or server side
  public List<A> AList { get; set; }
}

When we retrieve a record of B from the service, it contains the deserialized data of List<A> and the DateTime values are in UTC as stored in the database.

When the WebServiceClient returns the response, that deserialized data of List<A> now contains DateTime values in Local, not in UTC.

All other data DateTime handling is fine. i.e. We send, store, and receive in UTC always, leaving it up to our applications to manage how that data gets presented.

We tried using the same JsConfig.Init() content before client instantiation that the hosts use with no change behavior.

Any suggestions on a means to address this issue?

You can find JSON Configuration options in JSON Format docs, e.g. to skip conversion to LocalTime use:

JsConfig.Init(new Config {
    SkipDateTimeConversion = true,
});

To convert dates to UTC you can use:

JsConfig.Init(new Config {
    AlwaysUseUtc = true,
});

Yes, we’re doing that on the service side:

JsConfig.Init(new Config
{
   DateHandler = DateHandler.ISO8601,
   SkipDateTimeConversion = true,
   TextCase = TextCase.CamelCase
});

If you want it to assume unspecified dates are in UTC you’ll want to add AssumeUtc = true. If you want them converted to UTC add AlwaysUseUtc = true.

You’ll also need to configure the client for the behaviour that you want.

Yep, I added the same JsConfig from the service side to the client side in the correct application base class during DI configuration and it now works. Thank you, mythz!

1 Like