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

Implicit null is interpreted as empty string #716

Open
flobernd opened this issue Aug 25, 2022 · 2 comments
Open

Implicit null is interpreted as empty string #716

flobernd opened this issue Aug 25, 2022 · 2 comments
Labels

Comments

@flobernd
Copy link

flobernd commented Aug 25, 2022

Hi, I' using version 12.0.0 and have the following YAML:

on:
  implicit:
  explicit: null
  empty-string: ''

During deserialization, the implicit null value of workflow_dispatch gets interpreted as an empty string "":

Deserializer.Deserialize<YamlMappingNode>(reader)
on:
  implicit: ''
  explicit: null
  empty-string: ''

Same thing can be observed during serialization when I manually create a YamlScalarNode with a null value.

For the low level representation as Yaml{*}Node I would expect the original format to get preserved. If there was an explicit null it should re-serialize as explicit null and if there was an implicit null, it should re-serialize as implicit null. In no case should it re-serialize as "" imho.


When using Dictionary<object, object> instead of YamlMappingNode as the target type for the deserialization method, everything seems to work fine. Explicit null values are emitted as implicit ones at the end, but that's fine in this case I guess.

Deserializer.Deserialize<Dictionary<object, object>>(reader)
on:
  implicit: 
  explicit: 
  empty-string: ''
@flobernd flobernd changed the title null is interpreted as empty string Implicit null is interpreted as empty string Aug 25, 2022
@EdwardCooke EdwardCooke added the bug label Sep 8, 2022
@EdwardCooke
Copy link
Collaborator

As for reserializing explicit null to implicit null, once the yaml document is converted to a dot net object we no longer have how it was represented in the yaml document. It's a dot net limitation, we can't safely add arbitrary properties to an object. Not that I am aware of anyways, so we can't re-serialize exactly to what it was, just what is considered valid yaml.

As for deserializing an implicit null to an empty string instead of null, you are correct, that is a bug that needs to be addressed. I'm adding the bug tag so we can look at it. If you want to take a stab at it and submit a PR then that would be great.

@EdwardCooke
Copy link
Collaborator

I put in a fix for something similar to this issue in the last release (might have been the one before). Can you confirm if this is still a problem or not? If it is can post a complete code example to reproduce it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants