1

I have a number of legacy services in a ServiceStack 3 based middleware application which use the default date serialization format for JSON. The issue is that this is not human readable for debugging.

I would like a new service that is being tested to have human readable dates, which the ISO8061 format can do.

How can I change, for ServiceStack 3, the JSON date serialization format for a single service or on a service by service basis? I don't want to have to revalidate the consumers for all legacy services with a new date format.

....

Note: I have found an answer for ServiceStack 4, but the option to create a ResponseScope on an HttpResult does not seem to exist in ServiceStack 3.

SAJ14SAJ
  • 1,698
  • 1
  • 13
  • 32
  • What have you tried so far..? What's your current output and what's your expected output? – Geoff James Dec 01 '16 at 14:53
  • @GeoffJames the question is specific. SS3 doesn't use the ISO8601 format that's become a standard. There was no date standard back then. An early attempt by Microsoft used a unix timestamp enclosed in some weird tags to prevent deserialization as an integer. The OP is asking how to make SS3 return ISO8601 – Panagiotis Kanavos Dec 01 '16 at 14:56
  • I know how to set `JsConfig.DateHandler = JsonDateHandler.ISO8601` in the global config. Unfortunately, this would affect all legacy services requiring them to be revalidated. I would like to control the JSON date serialization (or better yet, the entire JSON config) on a service by service basis. – SAJ14SAJ Dec 01 '16 at 14:58
  • @PanagiotisKanavos -- Thats fair enough, thank you. But I ask just so we might be able to see some examples of the ISO8061 standard, and what the OP has already tried doing in order to get round this issue? – Geoff James Dec 01 '16 at 14:58
  • @GeoffJames ISO8601 is a very well known standard. – Panagiotis Kanavos Dec 01 '16 at 15:06
  • @SAJ14SAJ looking at the [source](https://github.com/ServiceStack/ServiceStack.Text/blob/e600c8ad7ee4593174f255838a0abf04abbe19ce/src/ServiceStack.Text/JsConfig.cs#L200), I see you can create a JsConfigScope to limit changes. Googling for JsConfigScope returns SO questions [like this one](http://stackoverflow.com/questions/13844796/is-it-possible-to-scope-servicestack-text-jsconfig-settings-to-just-your-library) that show how to use a JsConfigScope – Panagiotis Kanavos Dec 01 '16 at 15:16

1 Answers1

2

Looking at the source of JsConfig and similar SO questions I see that you can use a JsConfigScope to limit the scope of Json settings. Perhaps you can write something like :

using(var config = JsConfig.With(dateHandler=JsonDateHandler.ISO8601))
{
    ...
}
Community
  • 1
  • 1
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236