This project has moved and is read-only. For the latest updates, please go here.

Accessing existing property value from JsonConverter.ReadJson

Feb 28, 2010 at 7:36 PM

Im trying to serialize/deserialize an object graph like this:

class ObjA
    public int Id;
    public string Descriptopn;
    ICollection<ObjA> InnerA = new List<ObjA>();

What i need is the following JSON
    Key: 1,
    Name: "blahblah",
    InnerA: [
            Id: 2,
            Description: "something"
            Id: 3,
            Description: "something else"

So i need to use CustomJsonConverter to control how InnerA property is serialized. The problem is that i want to fill initialized InnerA collection, but now i can only create a new collection and return it from JsonConverter.ReadJson.

Looking at the code i see that it will be very easy to add a parameter to JsonConverter.ReadJson with the current value for the property.

I've prepared a patch for this.

What do you think?

Mar 17, 2010 at 8:29 AM

Done. Turned out to be surprisingly difficult to insure the existing value was always passed to the converter.