This project is read-only.

Is fastJSON supports "preserve reference" or "Cyclic reference"?

Oct 25, 2013 at 11:05 AM
As it is in JSON.NET, is fastJSON supports "preserve reference". Any help would be greatly appreciated.
Oct 25, 2013 at 11:09 AM
What do you mean?
Oct 26, 2013 at 7:26 PM
MGholam wrote:
What do you mean?
Hi MGholam,

Let me put an example here.

public class Customer{
public List<Order> Orders {get; set;}

public class Order{
public Customer CustomerInfo {get; set;}

Here, Customer has Orders and Order has Customer, so its cyclic. I had tried with a cyclic example, but the serialization failed with fastJSON. So, i thought of checking in the forum, are there any workaround/settings exists as such.
Oct 27, 2013 at 7:08 AM
No, fastJSON does not currently support cyclical references.
Marked as answer by lakswin on 12/2/2013 at 10:36 AM
Dec 2, 2013 at 7:49 AM
If it doesn't support cyclic references, then the web page describing it shouldn't list one of the pro's as "does everything JSON.NET does". Meanwhile, JSON.NET is so full of bugs and limitations I can barely use it, but at least it embeds an "$id" and can preserve references to handle cyclic references. I can't understand why these libraries are so overly complex and so full of limitations. JSON.NET's source code is very hard to follow, and by hard to follow, I mean very inconsistent in the order it checks for contracts and when/whether it checks for customer converters, which leads to a lot of failures. For example, it can't even deserialize a top-level object with an embedded "$type", because it can't find the converter for it unless you explicitly tell it the type up front, and it can't serialize a simple object array and deserialize it when preserving references, and instead throws an error about the array not being created from a default constructor, which is bogus. It seems like the only one I can trust is one I write myself.
Dec 2, 2013 at 1:28 PM
Clarification : "does everything does at the time of writing [ v4]" , cyclical references was add later I believe in v5.

I have a hard time seeing the case for complex cyclical serialization into json (other than for storage of MS objects which seem to thrive on referencing parents and children every where) most object structures for storage are relatively flat.
Dec 2, 2013 at 6:36 PM
Hi @triynko and @MGholam,

Yes, fastJSON doesn't supports cyclic reference.

Because of "$type" with JSON.NET, its hard to deserialize at the receiving end of the data. We have to have custom parsing for the same. Anyway, at least JSON.NET preserves the cyclic reference, when compare to other JSON serializers.

Thanks guys for your replies.
Sep 15, 2014 at 8:02 AM
Cyclic references are supported from v2.1.0
Marked as answer by MGholam on 9/15/2014 at 12:02 AM