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

null values are removed from list #29

Closed
bj0 opened this issue May 21, 2013 · 3 comments
Closed

null values are removed from list #29

bj0 opened this issue May 21, 2013 · 3 comments

Comments

@bj0
Copy link

bj0 commented May 21, 2013

If you serialize a list of nullable objects, the objects set to null are removed from the list:

var obj = new string[] { "one", null, "three", null, "four" };
var tw = new StringWriter();
(new Serializer()).Serialize(tw, obj);
Console.WriteLine(tw.ToString());

returns

- one
- three
- four

Instead, it should use the "null" value from the yaml spec, section 10.2.1.1. Null

- one
- null
- three
- null
- four

Otherwise lengths and positions of array elements can be lost.

roji pushed a commit to roji/YamlDotNet that referenced this issue May 22, 2013
@roji
Copy link
Contributor

roji commented May 22, 2013

@aaubry:

Reproduced in unit testing here: roji@7642951

The problem is that when EmitDefaults is false (the default), the DefaultExclusiveObjectGraphVisitor skips all nulls/defaults, regardless of whether they're in a collection or not.

I think it is difficult to resolve this issue with the current design, where default exclusion happens in a visitor (which has no context of where it is in the object graph. In roji@9fe1e94, I moved the default exclusion logic from the visitor to the TraversalStrategy, where much more context is available. I think that would be the correct solution to this bug as well.

The other alternative is to track graph context information inside the visitor (based on calls to VisitSequenceStart, VisitMappingStart), but that seems needless and complicated to me...

If you're OK with moving the default exclusion logic to the TraversalStrategy, I can submit a pull request fixing this.

@aaubry
Copy link
Owner

aaubry commented May 25, 2013

Actually this one was a simple bug in the visitor. It has been fixed on commit e9019d5.

@aaubry aaubry closed this as completed May 25, 2013
@roji
Copy link
Contributor

roji commented May 26, 2013

Oops, 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

3 participants