Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When serializing a Uri property in type it serializes as [Circular reference detected, object not serialized] #307

Open
tully2003 opened this issue Sep 19, 2016 · 1 comment

Comments

@tully2003
Copy link

I noticed that anytime an object contained an URI it would be serialized as [Circular reference detected, object not serialized].

I am using v5.3.1 and was able to recreate when running that code, the below error should allow you to experience the issue.

[Test]
public void UriSerializingAsCircularReference()
{
    Request r = new Request { Uri = new Uri("https://api.twitter.com") };

    string json = SimpleJson.SerializeObject(r);

    Assert.AreEqual("{\"Uri\":\"https://api.twitter.com\"}", json); // expected
    Assert.AreEqual("{\"Uri\":\"[Circular reference detected, object not serialized]\"}", json); // actual
}

public class Request
{
    public Uri Uri { get; set; }
}

After digging through the source the SerializeValue function in SimpleJson.cs (line 1016) is recursing back into itself adding Uri onto the visited stack again. The code that appears to be the culprit is located at line 1074 and is reproduced below.

object serializedObject;
success = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out serializedObject);
if (success)
    SerializeValue(jsonSerializerStrategy, serializedObject, builder, visited);
@QuantumNightmare
Copy link
Contributor

Thanks for pointing this out to us. We'll look into fixing this for the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants