Disable pointers when serializing?
reardonj opened this issue · 5 comments
Is there functionality to prevent Manatee.Json from creating pointers when serializing? (or even just for specified types?). I'm serializing some objects with Equals implementations that are causing occasional identical values to be serialized with pointers, but the other side can't deal with them.
Can you provide an example of when this happens, what you're getting, and what you expect, please?
Sure. The following program produces the output (.Net Fiddle): [{"TheValue":"test"},{"$ref":"#/0"}]
I would like to be able to produce [{"TheValue":"test"},{"TheValue":"test"}]
If I remove the Equals & GetHashCode implementations I get the desired behaviour, but that isn't an acceptable solution for my code.
using System;
public class Program
{
public static void Main()
{
var values = new Wrapper[] {new Wrapper { TheValue = "test"}, new Wrapper { TheValue = "test"}};
var serializer = new Manatee.Json.Serialization.JsonSerializer();
Console.WriteLine(serializer.Serialize(values).ToString());
}
}
public class Wrapper {
public string TheValue {get; set;}
public override bool Equals(object other) => other is Wrapper w && w.TheValue.Equals(this.TheValue);
public override int GetHashCode() => TheValue.GetHashCode();
}
Yeah, send like the string serializer might be trying to use referential integrity. This can be turned off completely (might have implications for recursion detection), but it definitely shouldn't be doing that for strings.
I'm not really maintaining this library anymore, though. If you like, you're welcome to submit a PR, and I'll review and merge it, but my focus has been on my new suite of libraries in the json-everything
repo.
How do I turn it off? Recursion won't be an issue.
Yeah, looks like I was mistaken. I thought there was a way to disable it, but it seems I didn't add that option.