Skip to content

Commit

Permalink
Fix bug when serializing lists with nulls inside.
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aubry committed May 25, 2013
1 parent bdcd103 commit e9019d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Expand Up @@ -21,8 +21,7 @@ private static object GetDefault(Type type)

public override bool Enter(object value, Type type)
{
return !_objectComparer.Equals(value, GetDefault(type))
&& base.Enter(value, type);
return base.Enter(value, type);
}

public override bool EnterMapping(object key, Type keyType, object value, Type valueType)
Expand Down
31 changes: 31 additions & 0 deletions YamlDotNet.UnitTests/RepresentationModel/SerializationTests.cs
Expand Up @@ -22,6 +22,7 @@
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using Xunit;
using System.IO;
using YamlDotNet.Core;
Expand Down Expand Up @@ -961,5 +962,35 @@ public void DefaultValueAttributeIsIgnoredWhenValueIsDifferent()

Assert.True(serialized.Contains("Value"));
}

[Fact]
public void NullValuesInListsAreAlwaysEmittedWithoutEmitDefaults()
{
var input = new string[] { "foo", null, "bar" };

var serializer = new Serializer();
var writer = new StringWriter();
serializer.Serialize(writer, input);
var serialized = writer.ToString();

Console.WriteLine(serialized);

Assert.Equal(3, Regex.Matches(serialized, "-").Count);
}

[Fact]
public void NullValuesInListsAreAlwaysEmittedWithEmitDefaults()
{
var input = new string[] { "foo", null, "bar" };

var serializer = new Serializer();
var writer = new StringWriter();
serializer.Serialize(writer, input, SerializationOptions.EmitDefaults);
var serialized = writer.ToString();

Console.WriteLine(serialized);

Assert.Equal(3, Regex.Matches(serialized, "-").Count);
}
}
}

0 comments on commit e9019d5

Please sign in to comment.