-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
Does YamlDotNet expose Yaml data type information in the API? #6
Comments
The only information that is available is the tag. If no tag is specified, it is up to the application to decide how to interpret the scalars. Also, the mapping between tags and types is left to the consumer of the parser. For example, the serializer uses information from the type of the object that is being deserialized to make that decision. |
Thank you for the response and the information. In my situation I'm not deserializing into custom typed objects, so there is no destination type information. Rather, I am recursing the Yaml nodes and converting them into a tree based on type as decided by the Yaml spec (code here). I am unable to make a decision on the type based on the scalar value, as there is no distinction between a Yaml int scalar and a Yaml string scalar . The Yaml spec (or wikipedia at least) says that |
I understand your requirement. I did not know about this, but there is a reference to this behavior in the specification. Right now there is no support for this, so if you require it you will need to implement it yourself. You should be able to use the Style property of YamlScalarNode to detect the quoting style of the node. The other types can be determined using regular expressions. |
Antoine, thank you for pointing out the Style property! I had totally missed that. |
Does YamlDotNet have any API for determining the data type of a YamlScalarNode? I was just looking at the Wikipedia on Yaml data types and was hoping that this type information was available via the YamlDotNet API http://en.wikipedia.org/wiki/YAML#Data_types - Is it? Thanks.
-- Update - I see that when type is explicitly defined in the Yaml the YamlNode.Tag is set (e.g. tag:yaml.org,2020:float when yaml contains !!float 123). However, it is null when no explicit type information is present.
The text was updated successfully, but these errors were encountered: