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

Json Compatible Serialization does not produce JSON for nodes. #906

Open
ShiJbey opened this issue Feb 12, 2024 · 0 comments
Open

Json Compatible Serialization does not produce JSON for nodes. #906

ShiJbey opened this issue Feb 12, 2024 · 0 comments

Comments

@ShiJbey
Copy link

ShiJbey commented Feb 12, 2024

Describe the bug

I want to serialize a large tree of YamlNodes to a JSON string, but it seems that the Serializer either:

  1. Outputs YAML instead of JSON when attempting to serialize a YamlNode
  2. Outputs JSON with unexpected additional information ("RootNode" and "AllNodes") when attempting to serialize the same node wrapped in a YamlDocument

I want to manually create the node trees because of my game's structure. Creating serialized "proxy" objects feels like too much, but seems to be the only supported serialization route. I appreciate your help.

To Reproduce

The toy example below recreates both problems. For reference, I'm using version 15.1.1 binaries loaded into Unity. I first encountered the problem while using the Unity asset store package. I recently tried the binaries and still had the same problem.

YamlMappingNode node = new YamlMappingNode()
{
	{"ingredients", new YamlSequenceNode() { "sugar", "water", "purple" } }
};

YamlDocument doc = new YamlDocument(node);

var serializer = new SerializerBuilder()
	.JsonCompatible()
	.Build();

// Swap for Console.Write();

Debug.Log(serializer.Serialize(node));

Debug.Log(serializer.Serialize(doc));

The code above outputs the following to the console.

ingredients:
- sugar
- water
- purple
{"RootNode": {ingredients: [sugar, water, purple]}, "AllNodes": [{ingredients: [sugar, water, purple]}, ingredients, [sugar, water, purple], sugar, water, purple]}
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

1 participant