Serialization depth

Jan 2, 2009 at 1:27 PM
Hi, first, sorry for my english =P.

I'm new to Json.Net and I've been playing with it a little, well here is my case and my question:

I want to serialize an object but this object has many objects associated with it, and those objects have associations too, wich gives me a huge Json as result , the problem is that i want only a small portion of that data, say only the root object and the next level of depth. I can't use the JsonIgnore attribute because this will cause to be permanently ignored.

It s possible to specify the depth of the serialization process?

Coordinator
Jan 3, 2009 at 11:56 AM
No. You will have to write a JsonConverter for that type to get the custom serialization behavior you want.
Jan 3, 2009 at 2:28 PM
Hi James, 

Thank you for your early answer, I'd really apreciate that. I need to do this for almost every domain object (it is an application that starts and already have more than 20 domain objects and it will be much more) in my application, what do you recommend me, the JsonConverter or inherit the JsonTextWriter to implement this behaviour?


Thank You
TrentCioran
Jan 3, 2009 at 10:44 PM
Hi,

I have modified the JsonSerializer to only serialize a graph to the N-th level if someone wants the code please let me know.

Cheers
TrentCioran
Jan 16, 2009 at 6:05 AM
Hi,

I am facing the same issue, and due to the depth of levels I get a stackoverflow error, I not sure whether depth would be the reason, however it would be nice if you could share the code.

Thanks
Mustafa
Jan 17, 2009 at 3:25 PM
Sure Mustafa, only changes the JsonSerializerSettings and the JsonSerializer, i sent you an email with the classes. =)


TrentCioran

Mar 24, 2011 at 9:43 PM

Hi TrentCioran, would you be able to share this change with me ? I am trying to find if there is a simpler way to restrict the recursion depth rather than weriting a converter.

Mar 29, 2011 at 6:15 AM

Hi TrentCioran:

I get the same problem, can you share the code with me? 

email address : delicious.johnny.fee@gmail.com

thanks.

May 10, 2011 at 1:53 PM

Hi trentcioran,

I also got the same problem, could you please send me the code?

email address: chin[at]topicus.nl

Thanks!

May 12, 2011 at 2:04 PM

I'm interested as well.  Perhaps you could just post the code here for everyone?

Otherwise, my username at gmail dot com

May 12, 2011 at 2:15 PM

The code is hardly outdated (i made a fork almost 2 years ago) this weekend I have time, I will update the sources and post the code. Sorry for the dealyed response guys :)

 

May 19, 2011 at 2:47 AM

Sorry guys, I've been a little busy here is the code, i couldn't update it but well, better than nothing isn't it? as soon i get some time i'll come back with an updated version.

shared/6n3jt0e60t  this is in box net

 

Regards,

TrenCioran

Oct 1, 2014 at 7:47 PM
So, has anyone been able to do this?

I need to set a max depth on serializing an object. I never plan on deserializing it.