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

Roundtripping empty reference in flow mapping fails #666

Closed
krisrok opened this issue Jan 6, 2022 · 2 comments
Closed

Roundtripping empty reference in flow mapping fails #666

krisrok opened this issue Jan 6, 2022 · 2 comments

Comments

@krisrok
Copy link

krisrok commented Jan 6, 2022

Describe the bug
Essentially, when serializing a null reference inside of a flow mapping its value gets translated to "". This in turn cannot be deserialized back to a given type, throwing an InvalidCastException.

So {Foo: ""} cannot be deserialized into a class class Bar { public Bar Foo }.
Instead {Foo: } (without the empty quotes) get deserialized just fine.

I don't know if that should be tackled inside the serialization or deserialization part, neither my YAML- nor my YamlDotNet-knowledge is sufficient.

To Reproduce
I've added a quick test to demonstrate the behaviour: krisrok@4a84500

@EdwardCooke
Copy link
Collaborator

Thank you for the test cases. I'll start work on fixing this.

@EdwardCooke
Copy link
Collaborator

I just looked at this, it doesn't seem to be a problem any more. I used your test case, with the flow emitter it failed with what you showed. Without it, it worked fine. I used the following test case:

        [Fact]
        public void RoundtripEmptyReferenceWithFlowMapping()
        {
            var serializer = new SerializerBuilder()
                .Build();

            var deserializer = new DeserializerBuilder()
                .Build();

            var yaml = serializer.Serialize(new RoundtripClass());
            var deserialized = deserializer.Deserialize<RoundtripClass>(yaml);
            deserialized.Should().NotBeNull();
            deserialized.Foo.Should().BeNull();
        }

I'm closing this issue as the problem lies in an emitter created outside of yamldotnet.

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

2 participants