Removing the redundant requirement of having "fields property with empty array" for union types with no values.
Note : Values are optionals in the Discriminated Union Reference : http://msdn.microsoft.com/en-us/library/vstudio/dd233226(v=vs.100).aspx
This commit is contained in:
@@ -42,7 +42,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(Currency.AUD);
|
||||
|
||||
Assert.AreEqual(@"{""Case"":""AUD"",""Fields"":[]}", json);
|
||||
Assert.AreEqual(@"{""Case"":""AUD""}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -56,10 +56,10 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
[Test]
|
||||
public void DeserializeBasicUnion()
|
||||
{
|
||||
Currency c = JsonConvert.DeserializeObject<Currency>(@"{""Case"":""AUD"",""Fields"":[]}");
|
||||
Currency c = JsonConvert.DeserializeObject<Currency>(@"{""Case"":""AUD""}");
|
||||
Assert.AreEqual(Currency.AUD, c);
|
||||
|
||||
c = JsonConvert.DeserializeObject<Currency>(@"{""Fields"":[],""Case"":""EUR""}");
|
||||
c = JsonConvert.DeserializeObject<Currency>(@"{""Case"":""EUR""}");
|
||||
Assert.AreEqual(Currency.EUR, c);
|
||||
|
||||
c = JsonConvert.DeserializeObject<Currency>(@"null");
|
||||
@@ -96,12 +96,6 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<Currency>(@"{""Fields"":[1]}"), "No 'Case' property with union name found. Path '', line 1, position 14.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeBasicUnion_NoFields()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<Currency>(@"{""Case"":""AUD""}"), "No 'Fields' property with union fields found. Path '', line 1, position 14.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeBasicUnion_UnexpectedEnd()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user