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

Enum name "Null" can not desiriaize #304

Closed
YoshihiroIto opened this issue Mar 8, 2018 · 1 comment · Fixed by #769
Closed

Enum name "Null" can not desiriaize #304

YoshihiroIto opened this issue Mar 8, 2018 · 1 comment · Fixed by #769
Assignees
Labels

Comments

@YoshihiroIto
Copy link

YamlDotNet 4.3.1

If enum member name "Null" , Deserialization will fail.

    public enum SomeEnum
    {
        Abc,
        Null
    }

    public class SomeClass
    {
        public SomeEnum Prop { get; set; }
    }

    class Program
    {
        static void Main()
        {
            var srcObj = new SomeClass
            {
                Prop = SomeEnum.Null
            };

            var sw = new StringWriter();
            new Serializer().Serialize(sw, srcObj);

            var yaml = sw.ToString();
            var dstObj = new Deserializer().Deserialize<SomeClass>(yaml);

            Debug.Assert(dstObj.Prop == SomeEnum.Null);
        }
    }

@EdwardCooke
Copy link
Collaborator

I'll work on this over the next little bit as it's still an issue. The WithQuotingNecessaryStrings isn't being applied to enum values.

using YamlDotNet.Serialization;


var srcObj = new SomeClass
{
    Prop = SomeEnum.Null
};

var yaml = new SerializerBuilder()
    .WithQuotingNecessaryStrings()
    .Build()
    .Serialize(srcObj);
Console.WriteLine(yaml);
var dstObj = new Deserializer().Deserialize<SomeClass>(yaml);

Console.WriteLine(dstObj.Prop);

public enum SomeEnum
{
    Abc,
    Null
}

public class SomeClass
{
    public SomeEnum Prop { get; set; }
}

Results:

Prop: Null

Abc

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

Successfully merging a pull request may close this issue.

3 participants