Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the ServiceStack.Text-equivalent of Json.NET Converters, for example when applied to NodaTime types?

How can I control the serialization/deserialization of custom types (such as NodaTime.LocalDateTime) with ServiceStack.Text?

Json.NET provides Converters for this, so that each time a class contains a custom type, the corresponding custom serializer/deserializer will be used. For example a property of type NodaTime.LocalDateTime can be converted to and from a string using custom methods.

In db4o, IObjectConstructor would act as a similar translation layer to convert a type to another before it is persisted (LocalDateTime could be converted to DateTime).

like image 459
Erwin Mayer Avatar asked Nov 03 '13 19:11

Erwin Mayer


1 Answers

You should use JsConfig<T>.RawSerializeFn and JsConfig<T>.RawDeserializeFn properties.

JsConfig<NodaTime.LocalDateTime>.RawSerializeFn = dateTime => { 
                                                      //your implemetation
                                                  } ;
like image 89
Ufuk Hacıoğulları Avatar answered Nov 15 '22 14:11

Ufuk Hacıoğulları