-Fixed using JArray with ImpromptuInterface by changing some members from explicit to public
-Fixed deserializing non-ISO date dictionary keys -Fixed values not being set when deserializing with DefaultValueHandling.IgnoreAndPopulate
This commit is contained in:
@@ -75,4 +75,4 @@ using System.Security;
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.4.16030")]
|
||||
[assembly: AssemblyFileVersion("5.0.4.16101")]
|
||||
|
||||
@@ -147,6 +147,33 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual("TestProperty1Value", c.TestProperty1);
|
||||
}
|
||||
|
||||
public class DefaultHandler
|
||||
{
|
||||
[DefaultValue(-1)]
|
||||
public int field1;
|
||||
|
||||
[DefaultValue("default")]
|
||||
public string field2;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeIgnoreAndPopulate()
|
||||
{
|
||||
DefaultHandler c1 = JsonConvert.DeserializeObject<DefaultHandler>("{}", new JsonSerializerSettings
|
||||
{
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
|
||||
});
|
||||
Assert.AreEqual(-1, c1.field1);
|
||||
Assert.AreEqual("default", c1.field2);
|
||||
|
||||
DefaultHandler c2 = JsonConvert.DeserializeObject<DefaultHandler>("{'field1':-1,'field2':'default'}", new JsonSerializerSettings
|
||||
{
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
|
||||
});
|
||||
Assert.AreEqual(-1, c2.field1);
|
||||
Assert.AreEqual("default", c2.field2);
|
||||
}
|
||||
|
||||
[JsonObject]
|
||||
public class NetworkUser
|
||||
{
|
||||
|
||||
@@ -8687,6 +8687,17 @@ Parameter name: value",
|
||||
Assert.AreEqual(2, list[1]);
|
||||
Assert.AreEqual(0, list[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeNonIsoDateDictionaryKey()
|
||||
{
|
||||
Dictionary<DateTime, string> d = JsonConvert.DeserializeObject<Dictionary<DateTime, string>>(@"{""04/28/2013 00:00:00"":""test""}");
|
||||
|
||||
Assert.AreEqual(1, d.Count);
|
||||
|
||||
DateTime key = DateTime.Parse("04/28/2013 00:00:00", CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual("test", d[key]);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Antworten
|
||||
|
||||
@@ -271,6 +271,17 @@ namespace Newtonsoft.Json.Linq
|
||||
RemoveItemAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the collection.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection.
|
||||
/// </returns>
|
||||
public IEnumerator<JToken> GetEnumerator()
|
||||
{
|
||||
return Children().GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICollection<JToken> Members
|
||||
@@ -306,12 +317,21 @@ namespace Newtonsoft.Json.Linq
|
||||
return ContainsItem(item);
|
||||
}
|
||||
|
||||
void ICollection<JToken>.CopyTo(JToken[] array, int arrayIndex)
|
||||
/// <summary>
|
||||
/// Copies to.
|
||||
/// </summary>
|
||||
/// <param name="array">The array.</param>
|
||||
/// <param name="arrayIndex">Index of the array.</param>
|
||||
public void CopyTo(JToken[] array, int arrayIndex)
|
||||
{
|
||||
CopyItemsTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
bool ICollection<JToken>.IsReadOnly
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.
|
||||
/// </summary>
|
||||
/// <returns>true if the <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only; otherwise, false.</returns>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
@@ -92,6 +92,6 @@ using System.Security;
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.4.16030")]
|
||||
[assembly: AssemblyFileVersion("5.0.4.16101")]
|
||||
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
@@ -808,6 +808,7 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
|
||||
// test tokentype here because default value might not be convertable to actual type, e.g. default of "" for DateTime
|
||||
if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer._defaultValueHandling), DefaultValueHandling.Ignore)
|
||||
&& !HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer._defaultValueHandling), DefaultValueHandling.Populate)
|
||||
&& JsonReader.IsPrimitiveToken(tokenType)
|
||||
&& MiscellaneousUtils.ValueEquals(reader.Value, property.GetResolvedDefaultValue()))
|
||||
return true;
|
||||
@@ -853,7 +854,8 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
return false;
|
||||
|
||||
if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer._defaultValueHandling), DefaultValueHandling.Ignore)
|
||||
&& MiscellaneousUtils.ValueEquals(value, property.GetResolvedDefaultValue()))
|
||||
&& !HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer._defaultValueHandling), DefaultValueHandling.Populate)
|
||||
&& MiscellaneousUtils.ValueEquals(value, property.GetResolvedDefaultValue()))
|
||||
return false;
|
||||
|
||||
if (!property.Writable)
|
||||
@@ -975,15 +977,18 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
{
|
||||
try
|
||||
{
|
||||
object dt;
|
||||
// this is for correctly reading ISO and MS formatted dictionary keys
|
||||
if ((keyTypeCode == PrimitiveTypeCode.DateTime || keyTypeCode == PrimitiveTypeCode.DateTimeNullable)
|
||||
&& DateTimeUtils.TryParseDateTime(keyValue.ToString(), DateParseHandling.DateTime, reader.DateTimeZoneHandling, out keyValue))
|
||||
&& DateTimeUtils.TryParseDateTime(keyValue.ToString(), DateParseHandling.DateTime, reader.DateTimeZoneHandling, out dt))
|
||||
{
|
||||
keyValue = dt;
|
||||
}
|
||||
#if !NET20
|
||||
else if ((keyTypeCode == PrimitiveTypeCode.DateTimeOffset || keyTypeCode == PrimitiveTypeCode.DateTimeOffsetNullable)
|
||||
&& DateTimeUtils.TryParseDateTime(keyValue.ToString(), DateParseHandling.DateTimeOffset, reader.DateTimeZoneHandling, out keyValue))
|
||||
&& DateTimeUtils.TryParseDateTime(keyValue.ToString(), DateParseHandling.DateTimeOffset, reader.DateTimeZoneHandling, out dt))
|
||||
{
|
||||
keyValue = dt;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user