Search code examples
c#jsonservicestack-text

Servicestack.Text not parsing json


I'm reading a json from file and serializing to any object as follows:

MyObject o = myjson.FromJson<MyObject>();

The json text is correct as I was using Newtonsoft.Json before moving to ServiceStack.

However, after serializing, the object 'o' is not being set accordingly (ie. empty or with default values set in the object's constructor).

The is the class:

public class Options
{
    public string Email;
    public string Password;
    public string Answer;
    //etc...

    public Options()
    {
        this.Email = "default";
        this.Password = "default";
        //etc...
    }
}

What can be wrong?


Solution

  • ServiceStack doesn't serialize public fields by default, but you can enable it with:

    JsConfig.IncludePublicFields = true;