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

Yaml creation error #73

Closed
liuyl1992 opened this issue Jan 17, 2020 · 5 comments
Closed

Yaml creation error #73

liuyl1992 opened this issue Jan 17, 2020 · 5 comments

Comments

@liuyl1992
Copy link

image
result:
image

@ghost
Copy link

ghost commented Jan 26, 2020

I have a similar issue. No clue how to resolve it, and it's seriously bothering me during development on my own project.

@ghost
Copy link

ghost commented Jan 26, 2020

I've tracked this down to AnchorSerializer.cs. Disabling anchoring and aliases would resolve this issue, yet I cannot find any documentation on how to do this.

@ghost
Copy link

ghost commented Jan 26, 2020

YamlSharp.Serializer.Settings.EmitAlias is set to 'true' by default. I thought setting it to 'false' would disable this behavior, but rather, it increased it. Now, every variable was given an anchor tag, due to the fact that aliases (but no anchors) were now disabled. @xoofx, is there really no way to outright disable outputting anchors when Serializer.Serialize(object) is called?

@ghost
Copy link

ghost commented Jan 26, 2020

Issue #15 ("How do I get Serialize() to stop putting out anchor and reference labels?") was about this same thing, actually, and the response of setting 'SortKeyForMapping' and 'EmitAlias' both to false before serializing simply does not resolve this (at least not anymore). For now, switching to JSON over YAML seems like a good option due to readability concerns.

@xoofx
Copy link
Owner

xoofx commented Jan 26, 2020

You have to use SerializerSettings and disable aliasing.

using System;
using SharpYaml.Serialization;

namespace SharpYaml.Tests
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var settings = new SerializerSettings {EmitAlias = false};
            var serializer = new Serializer(settings);
            var tester = new Tester() { A = "this is a", B = "this is a"};
            var text = serializer.Serialize(tester);
            Console.WriteLine(text);
        }

        public struct Tester
        {
            public string A { get; set; }

            public string B { get; set; }
        }
    }
}

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

No branches or pull requests

2 participants