Arxisos
Arxisos

Reputation: 2729

Why do ServiceStack.Text custom deserialization settings not apply?

I use ServiceStack.Text with ServiceStack (the web service framework).

I'm trying to add a custom serialization route for a specific type in AppHost.Configure(). However, the settings do not apply/are ignored.

public AppHost : AppHostBase 
{
    ...

    public override void Configure(Container container)
    {
        //Register custom serialization routine
        ServiceStack.Text.JsConfig<CultureInfo>.SerializeFn = r => r.TwoLetterISOLanguageName;
        ServiceStack.Text.JsConfig<CultureInfo>.DeSerializeFn = r => return new CultureInfo(r);    
    }
}

Upvotes: 5

Views: 1136

Answers (1)

Arxisos
Arxisos

Reputation: 2729

ServiceStack.Text is caching internally very heavily to achieve fast performance. ServiceStack is already starting the cache creation process before AppHost.Configure() is called.

So to resolve this issue, you need to register your settings before AppHost.Init() is called.

Of course this isn't required for all settings in ServiceStack.Text - it's only required for the settings which will be cached before AppHost.Configure() is called.

Upvotes: 7

Related Questions