문제

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).

도움이 되었습니까?

해결책

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

JsConfig<NodaTime.LocalDateTime>.RawSerializeFn = dateTime => { 
                                                      //your implemetation
                                                  } ;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top