Merge pull request #24 from roji/deserialize_null

Null is now properly deserialized
This commit is contained in:
Antoine Aubry 2013-05-05 08:59:03 -07:00
Родитель c455be2f02 9335f00628
Коммит e0ddf98657
2 изменённых файлов: 36 добавлений и 9 удалений

Просмотреть файл

@ -335,21 +335,19 @@ namespace YamlDotNet.RepresentationModel.Serialization
private bool IsNull(NodeEvent nodeEvent)
{
// http://yaml.org/type/null.html
if (nodeEvent.Tag == "tag:yaml.org,2002:null")
{
return true;
}
if (JsonCompatible)
{
var scalar = nodeEvent as Scalar;
if (scalar != null && scalar.Style == Core.ScalarStyle.Plain && scalar.Value == "null")
{
return true;
}
}
if (scalar == null)
return false;
var value = scalar.Value;
return value == "" || value == "~" || value == "null" || value == "Null" || value == "NULL";
}
private object DeserializeValueNotNull(EventReader reader, DeserializationContext context, INodeEvent nodeEvent, Type expectedType)

Просмотреть файл

@ -197,6 +197,35 @@ namespace YamlDotNet.UnitTests.RepresentationModel
}
}
[Fact]
public void RoundtripWithDefaults()
{
var serializer = new Serializer();
using (StringWriter buffer = new StringWriter())
{
X original = new X();
serializer.Serialize(buffer, original, SerializationOptions.Roundtrip | SerializationOptions.EmitDefaults);
Console.WriteLine(buffer.ToString());
var deserializer = new YamlSerializer(typeof(X), YamlSerializerModes.Roundtrip);
X copy = (X)deserializer.Deserialize(new StringReader(buffer.ToString()));
foreach (var property in typeof(X).GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (property.CanRead && property.CanWrite)
{
Assert.Equal(
property.GetValue(original, null),
property.GetValue(copy, null)
);
}
}
}
}
private class Y
{
private Y child;