Partial Deserialization

Jul 30, 2009 at 4:06 PM

I have JSON that looks like this:

{"action":"MyApp","method":"MyMethod","data":["Param1":"mystring","Param2":123,"Param3":{"Prop1":"abc","Prop2":"qwer"}]}

That I would like deserialize into a class that looks like this:

[JsonObject]
internal class DirectRequest
{
        public string Action
        {
            get;
            set;
        }

        public string Method
        {
            get;
            set;
        }

        public string Data
        {
            get;
            set;
        }
}

Where DirectRequest.Data is populated with the JSON string "[\"Param1\":\"mystring\",\"Param2\":123,\"Param3\":{\"Prop1\":\"abc\",\"Prop2\":\"qwer\"}]".

In other words, is there a way to partially deserialize JSON so that one property just gets the JSON string passed through?

Do I have to write my own custom converter for the Data property that "recreates" the JSON string?

Coordinator
Jul 31, 2009 at 9:00 AM

You'll need to write your own custom converter. It should be pretty easy. Load the JsonReader inside the customer into a JObject and then pick out the Action and Method values. For Data just do a to ToString() on the JArray that it returns. That will give you its JSON text.