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

Deserializing multiple documents does not work #874

Closed
JacekArdanowski opened this issue Nov 27, 2023 · 2 comments
Closed

Deserializing multiple documents does not work #874

JacekArdanowski opened this issue Nov 27, 2023 · 2 comments

Comments

@JacekArdanowski
Copy link

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:

  • 'ParserExtensions.Accept(IParser)' is obsolete: 'Please use TryConsume(out var evt) or Accept(out var evt) instead'
  • 'ParserExtensions.Expect(IParser)' is obsolete: 'Please use Consume() instead'

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
Copy link
Author

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
Copy link
Collaborator

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.

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