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

Does YamlDotNet expose Yaml data type information in the API? #6

Closed
bentayloruk opened this issue Nov 28, 2012 · 4 comments
Closed

Comments

@bentayloruk
Copy link

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.

@aaubry
Copy link
Owner

aaubry commented Nov 30, 2012

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.

@bentayloruk
Copy link
Author

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 a: 123 is an int and b: "123" is a string. However, I think both appear as "123" in YamlScalar.Value (and tag is null). Am I missing something? Is there anyway to figure this out? If not, would it be much work to tag these values with the appropriate type? (I'd be happy to help).

@aaubry
Copy link
Owner

aaubry commented Dec 4, 2012

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.

@bentayloruk
Copy link
Author

Antoine, thank you for pointing out the Style property! I had totally missed that.

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