How to use custom JSON Serializer in Servicestack?

I am wondering how you can use custom JSON Serializer in ServiceStack. I know JsConfig.SerializeFn / DeSerializeFn, but they always seem to be "JSON.stringify" the result of my custom Serializer.

I like replacing serialization for the whole DTO. The end result should be something like

{"Name":"Greg"} 

but not

 "{\"Name\":\"Greg\"}" 

Is it possible?

+6
source share
2 answers

In terms of other Serializer ServiceStack JSON hooks, there is also JsConfig<T>.RawSerializeFn and JsConfig<T>.RawDeserializeFn that should do what you need.

Otherwise, if you just want some pre / post processing to also execute the custom interceptors JsConfig<T>.OnSerializingFn and JsConfig<T>.OnDeserializedFn .

+7
source

Did you mean to use ServiceStack.Text.JsonSerializer.SerializeToString(object, typeof(object)) ? If you use it as .net, you may need to use Html.Raw(ServiceStack.Text.JsonSerializer.SerializeToString(object, typeof(object))) .

0
source

All Articles