Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Disable pointers when serializing? #288

Open
reardonj opened this issue Dec 3, 2020 · 5 comments
Open

Disable pointers when serializing? #288

reardonj opened this issue Dec 3, 2020 · 5 comments
Labels
question question A user has a question.

Comments

@reardonj
Copy link

reardonj commented Dec 3, 2020

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.

@gregsdennis
Copy link
Owner

Can you provide an example of when this happens, what you're getting, and what you expect, please?

@gregsdennis gregsdennis added the question question A user has a question. label Dec 3, 2020
@reardonj
Copy link
Author

reardonj commented Dec 3, 2020

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();

}

@gregsdennis
Copy link
Owner

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.

@reardonj
Copy link
Author

reardonj commented Dec 4, 2020

How do I turn it off? Recursion won't be an issue.

@gregsdennis
Copy link
Owner

Yeah, looks like I was mistaken. I thought there was a way to disable it, but it seems I didn't add that option.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question question A user has a question.
Projects
None yet
Development

No branches or pull requests

2 participants