6

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.

I like to replace Serialization for the whole DTO. The endresult should be something like

{"Name":"Greg"}

and not

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

Is that possible?

helge
  • 61
  • 1
  • 3

2 Answers2

7

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.

Otherwise if you just want to some pre/post processing there's also the JsConfig<T>.OnSerializingFn and JsConfig<T>.OnDeserializedFn custom hooks.

mythz
  • 141,670
  • 29
  • 246
  • 390
0

Did you mean to use ServiceStack.Text.JsonSerializer.SerializeToString(object, typeof(object))? If you using it in a view in .net you might need to use Html.Raw(ServiceStack.Text.JsonSerializer.SerializeToString(object, typeof(object))).

ecco88
  • 606
  • 2
  • 7
  • 16