-
-
Notifications
You must be signed in to change notification settings - Fork 486
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
Serializer misconverts "null" string to null value, "true" string to true value #387
Comments
The original issue was raised here: TeamYARM/YARM-CLI#1 |
I think YAML allows string value with/without the double quotation marks. If YamlDotNet forces to use double quotes for the string values, it could resolve this issue. |
It seems that this behavior could be improved, but I'll need some more time to look into it. |
@aaubry |
I'm not currently working on this, but I'm not sure either where to start implementing this, sorry. |
I've been looking at this a bit to try to come up with a reasonable solution, as I've had this same issue in my usage of YamlDotNet and am using it for data that I don't have control over so I really either (a) need it to work, or (b) use a different serialization library / format. I definitely prefer (a) of those two options..., so I thought I'd see if I could provide a patch. Here's my line of thinking on this:
Here are some examples (all things on the left are meant to be "strings" in type, but the LHS means what they 'look like'):
In these cases, doing something with a round trip via expandoObject (or in my case, just serializing to YAML and deserializing even causes problems with Null specifically) will produce incorrect types on the way "back in". I was thinking about the following:
Ex: if you have an expando object that has (string)1E10 in it, and you write that to YAML, it would be '1E10' instead of the "bare" 1E10 (if you have this flag set on the emitter options / serializer options). Thoughts? I'm happy to put in some time on making this work if someone discuss a couple build issues I'm having trying to get the build to work (it seems to be having problems building some of the other stuff on my machine, and some of the spec tests failed on the latest spec download from yaml-test-suite). |
This will be fixed when the next release goes out. |
Hi, Team.
I'm using YamlDotNet v5.4.0, which is the latest version at the time of this writing. I have a very simple JSON payload like:
As you can see, both
"null"
and"true"
are string, not literallynull
ortrue
value. Therefore, if I converted that JSON into YAML, the YAML file should look like:However, unlike the expectation, it actually returns:
How can I prevent those values from being converted, but left as string literal? I used the code like:
Obviously the last line
var yaml = new SerializerBuilder().Build().Serialize(deserialised);
doesn't return the correct value.Is there a workaround to prevent this?
The text was updated successfully, but these errors were encountered: