如何在Servicestack中使用自定义JSON序列化程序? [英] How to use a custom JSON Serializer in Servicestack?

查看:155
本文介绍了如何在Servicestack中使用自定义JSON序列化程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在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>.RawSerializeFnJsConfig<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>.OnSerializingFnJsConfig<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆