-Fixed empty strings coerced to null not erroring with Required.Always

This commit is contained in:
James Newton-King
2015-06-13 22:31:16 +12:00
parent b270104bfb
commit 70521eea88
3 changed files with 42 additions and 13 deletions
@@ -95,6 +95,21 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class JsonSerializerTest : TestFixtureBase
{
[Test]
public void CoercedEmptyStringWithRequired()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<Binding>("{requiredProperty:''}");
}, "Required property 'RequiredProperty' expects a value but got null. Path '', line 1, position 21.");
}
public class Binding
{
[JsonProperty(Required = Required.Always)]
public Binding RequiredProperty { get; set; }
}
public class DictionaryKeyContractResolver : DefaultContractResolver
{
protected override string ResolveDictionaryKey(string dictionaryKey)