aaubry / YamlDotNet

YamlDotNet is a .NET library for YAML
MIT License
2.48k stars 466 forks source link

Deserializing multiple documents does not work #874

Closed JacekArdanowski closed 7 months ago

JacekArdanowski commented 7 months ago

Describe the bug Hi, I'm trying to follow the tutorial here on how to deserialize multiple documents. I'm using YamlDotNet 13.7.0. I receive two warnings:

When using recommended methods, the same code snippet does not emit the second document.

To Reproduce

// Consume the stream start event "manually"
parser.Consume<StreamStart>();

while (parser.TryConsume<DocumentStart>(out var @event))
{
    // Deserialize the document
    var doc = deserializer.Deserialize(parser);
    var json = serializer.Serialize(doc);
}

Sample yaml:

---
name: test1
version: 1.2
---
name: test2
version: 1.2
---

What am I missing here? Thanks!

JacekArdanowski commented 7 months ago

Nevermind, I used Accept instead of TryConsume and it now works:

 // Consume the stream start event "manually"
 parser.Consume<StreamStart>();

 while (parser.Accept<DocumentStart>(out var @event))
 {
     // Deserialize the document
     var doc = deserializer.Deserialize(parser);
     var json = serializer.Serialize(doc);
 }
EdwardCooke commented 7 months ago

Thanks for pointing that out. I’ll get the docs updated soon. And probably mark those obsolete methods as hidden so the code doesn’t break but intellisense won’t show them.