Aaron
Aaron

Reputation: 599

How to override string serialization in ServiceStack.Text?

How come the following works to override Guid formatting:

ServiceStack.Text.JsConfig<Guid>.SerializeFn = guid => guid.ToString();

But doing this to force null strings to empty strings doesn't?

ServiceStack.Text.JsConfig<string>.SerializeFn = str => str ?? string.Empty;

I have this enabled:

ServiceStack.Text.JsConfig.IncludeNullValues = true;

I have also tried the String class rather than the string primitive. And the raw version named .RawSerializeFn

Is there a different work around?

Upvotes: 3

Views: 1214

Answers (1)

mythz
mythz

Reputation: 143319

String's are specially handled in ServiceStack.Text so you can't override their behavior with configuration.

Given you can't override it, the only solution I can see (other than submitting a pull-request) is to reflect over the model and populate null properties with empty strings.

Upvotes: 2

Related Questions