Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (44 sloc) 2.99 KB

NodaTime.Serialization.ServiceStackText

ServiceStack.Text JSON serialization support for NodaTime v2. This library will work with v5.0 and later versions of ServiceStack.Text and ServiceStack.Text.Core.

Typical Setup

DateTimeZoneProviders.Tzdb
  .CreateDefaultSerializersForNodaTime()
  .ConfigureSerializersForNodaTime();

Optional Setup

There are static extension methods to allow for optional fluent configuration.

Use Iso Interval Serializer

DateTimeZoneProviders.Tzdb.CreateDefaultSerializersForNodaTime()
  .WithIsoIntervalSerializer()
  .ConfigureSerializersForNodaTime();

Use Iso Period Serializer

DateTimeZoneProviders.Tzdb.CreateDefaultSerializersForNodaTime()
  .WithNormalizingIsoPeriodSerializer()
  .ConfigureSerializersForNodaTime();

One-Off Serializer Setup

//You could create you own serializer by implementing IServiceStackSerializer<T>
NodaSerializerDefinitions.LocalTimeSerializer.ConfigureSerializer();

Alternatively, you can create your own implementation of INodaSerializerSettings to suit your specific needs.

Default Serializers

The SerivceStack.Text serializer uses the same default serialization formats as those used in the Json.NET serializers. You can optionally change the Interval serializer to use the ISO 8601 Interval spec.

Notes

  • Serializer setup should only occur once in your application root.
  • Serialization setup should occur before any serialization occurs with ServiceStack.Text or there may be undesirable behavior.
  • If using with ServiceStack, serializer setup should occur before Init of the AppHost.
  • For Value types, this will also setup the nullable serializer for that value type.
  • Since this is a custom serializer for ServiceStack.Text, calls to JsConfig.Reset() will remove the custom serializers.

Using the Code

Continuous Integration

CodeBetter.com CI Build Status: Build Status

Special Thanks to JetBrains and CodeBetter for hosting this project!