Serialization differences with backwards compatibility

We’ve started re-writing our products backend APIs with ServiceStack - the old API was NancyFX.

My first task was to setup integration tests (for using both the old Refit interfaces as they were to ensure backwards compatibility, and the new JsonServiceClient impls).

I’ve hit one major snag that I’m unable to solve: The old system used snake case.

So when I do this:

JsConfig.TextCase = TextCase.SnakeCase;

I can authenticate and make API calls with the Refit APIs fine, but the JsonServiceClient calls fail with ‘User Name’ should not be null.

When I don’t set SnakeCase - the JsonServiceClient works fine but the old Refit APIs fail.

Is there a recommended path forward here? I’m trying my hardest not to modify the old clients serialization and the old APIs serialization.

Any ServiceStack.Text configuration should use JsConfig.Init() and only be initialized once on Startup:

JsConfig.Init(new Config { TextCase = TextCase.SnakeCase });

Do you have this configuration on both client & server? Are you using the JsonServiceClient to call a ServiceStack Service?

Yes, in my test case and my TestAppHost I have

JsConfig.Init(new Config { TextCase = TextCase.SnakeCase });

In one set of tests, I use refit interfaces to call the API (these work with TextCase.SnakeCase). In the other set of tests I am using JsonServiceClient (these don’t work - properties are null)

If properties are null it’s typically cause the JSON sent doesn’t match the wireformat that it expects.

If you need to force a specific property you can specify it with [DataMember(Name)] attribute, e.g:

public class MyRequest
    public string UserName { get; set; }