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

Serialization depth

Nov 10, 2009 at 5:10 PM

I'm quite new with your library and with JSON in general.
I'm using it to serialize and deserialize object exchanged between a client (a winforms application) and a server (ASP.NET/Monorail/ASPVIEW) over HTTP.

What I'm trying to accomplish: I'd like to tailor the depth of the data serialized in every view.

Suppose I have a Credential object that references a User object and a collection of Role objects. I a view I may want to serialize the user and the roles, in another just the roles and so on...

What I Know is that I should create a specialized JsonConverter, am I right? I thought I could feed the converted with a set of (something like) XPath strings (ie "/User" would mean to include the "User" property of the "root" object) to let it determine if a given property should be serialized or not in the given context.

JsonConvert.SerializeObject(item, Formatting.Indented, new JsonConverter[] {new Converter(includedPaths)});

This leads me to the following lines of code in my converter:

public override void WriteJson(JsonWriter writer, object value)
            throw new System.NotImplementedException();

I can't find a way to exactly determine what I'm serializing, because I can't imagine how to determine the current "path", I just know the value (and its type)...

Now the question: any suggestion?

Lorenzo Vegetti

Nov 10, 2009 at 9:27 PM

Store state on a class field.