如何在Servicestack中使用自定义JSON序列化程序? [英] How to use a custom JSON Serializer in Servicestack?
问题描述
我想知道如何在ServiceStack中使用自定义JSON序列化器.我知道JsConfig.SerializeFn/DeSerializeFn,但这些似乎总是对我自定义序列化器的结果进行"JSON.stringify".
I am wondering how you can use a custom JSON Serializer in ServiceStack. I am aware of the JsConfig.SerializeFn/DeSerializeFn but these seem to always 'JSON.stringify' the result of my custom Serializer.
我喜欢为整个DTO替换序列化.最终结果应该类似于
I like to replace Serialization for the whole DTO. The endresult should be something like
{"Name":"Greg"}
不是
"{\"Name\":\"Greg\"}"
有可能吗?
推荐答案
关于 ServiceStack的JSON序列化器还有JsConfig<T>.RawSerializeFn
和JsConfig<T>.RawDeserializeFn
应该可以满足您的需求.
In terms of other hooks in ServiceStack's JSON Serializers there's also JsConfig<T>.RawSerializeFn
and JsConfig<T>.RawDeserializeFn
which should do what you need.
否则,如果您只想进行一些前/后处理,则还有JsConfig<T>.OnSerializingFn
和JsConfig<T>.OnDeserializedFn
自定义钩子.
Otherwise if you just want to some pre/post processing there's also the JsConfig<T>.OnSerializingFn
and JsConfig<T>.OnDeserializedFn
custom hooks.
这篇关于如何在Servicestack中使用自定义JSON序列化程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!