-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Support for resolving deserialized objects to their line/ char positions #494
Comments
You can extend the various |
@djluck Did you managed to solve your problem using |
@aaubry - I'll have to respectfully disagree with you on the point this doesn't belong in the core library. Location information is a staple part of any parser technology. Providing a way to get access to the original source line and character position is key to properly reporting errors, not just in parsing but in later sematic analysis of the resulting data. There's no such thing as a schema to use for validation with YAML. Thus, code parsing YAML content needs to have a way to get at that information to report when things are syntactically correct, yet semantically incorrect. Forcing everyone into building their own deserializers for all such cases is brutal and pointlessly repetitions effort on library users that is much more easily resolved once, for all in the library itself. |
I ended up writing a project to help achieve the request- https://github.com/djluck/YamlDotNet.Locations. it's an early release so any feedback would be appreciated. |
One option is using these attributes on methods in your classes for validation. Throwing an exception would fail the serialization/deserialization which would include the start and ending position of the current element in the yaml file which seems like it will give you want. Closing this issue. https://github.com/aaubry/YamlDotNet/tree/master/YamlDotNet/Serialization/Callbacks |
I'm currently attempting to validate the deserialized output of a YAML file using YamlDotNet. There's a few types of validation I'd like to be able to do:
For each type of validation, I'd like to be able to give the exact file location of an invalid value. I've seen the validation sample in the wiki and while this works (and the idea could be extended to collections and dictionaries), it doesn't support fetching the position of invalid values- we can just throw exceptions for the final position of the deserialized item.
Looking at the codebase, I think it might be possible to extend the various
INodeDeserializer
implementations to emit positional information of property names & values/ dictionary keys & values and collection members. Before I attempt a PR, I'd like to hear thoughts on if this is a good idea or not or if there's an easier way to get what I want.The text was updated successfully, but these errors were encountered: