ServiceStack.Text way to customize Serialization/Deserialisation?

688 views
Skip to first unread message

Macro

unread,
Jun 1, 2012, 8:36:35 AM6/1/12
to ServiceStack .NET Open Source REST Web Services Framework
I am currently using your library as part of some automated tests, and
its great. However I have an issue where I am having to use enums
within the objects on one of the tests and when it is called in real-
life the JSON sent has the integer representations of the enum,
whereas this is serializing the text representation of the enum.

Is there any way to give it some arguments to infer how it should
serialize certain elements, or even ignore certain elements when
serializing?

This isn't end of the world if I cannot do the above, would just be
very helpful.

Demis Bellot

unread,
Jun 1, 2012, 9:33:01 AM6/1/12
to servic...@googlegroups.com
Hi, 

You can use the Enum [Flags] attribute, which when added on the Enum is serialized as an int, otherwise its serialized as text.

There's also JsConfig<T>.SerializeFn/DeserializeFn global handlers you can set to change the way built-in types are serialized.

Cheers,

Luke Pulverenti

unread,
Jul 15, 2012, 2:09:29 PM7/15/12
to servic...@googlegroups.com
What is the second param (string) in the SerializeFn delegate?

Luke Pulverenti

unread,
Jul 15, 2012, 2:14:03 PM7/15/12
to servic...@googlegroups.com
Is there a way I can provide a SerializeFn that works on top of your ouput?

So for instance, let's say I want to inject an additional property that may not be appropriate to put directly into my model classes. Is that possible? Thanks.


On Friday, June 1, 2012 8:36:35 AM UTC-4, Macro wrote:

Demis Bellot

unread,
Jul 15, 2012, 2:39:13 PM7/15/12
to servic...@googlegroups.com
The JsConfig<T>.SerializeFn/DeserializeFn is only for customizing the serialization process of ValueTypes.
There's no way to apply a post-serialization decoration of normal types, this would have to be applied to your models manually after its been deserialized.
Reply all
Reply to author
Forward
0 new messages