-Fixed exception message typo
-Fixed serializer sometimes not using DateParseHandling setting -Fixed error in JsonWriter.WriteToken when writing a DateTimeOffset -Fixed error when serializing emitted classes that have a constructor with null named parameters (really?)
This commit is contained in:
@@ -76,5 +76,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("4.5.9.15324")]
|
||||
[assembly: AssemblyFileVersion("4.5.9.15402")]
|
||||
#endif
|
||||
|
||||
@@ -1312,7 +1312,7 @@ keyword such as type of business.""
|
||||
String strFromTest = JsonConvert.SerializeObject(testClass);
|
||||
|
||||
ExceptionAssert.Throws<JsonSerializationException>(
|
||||
@"Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.ICo. Type is an interface or abstract class and cannot be instantated. Path 'co.Name', line 1, position 14.",
|
||||
@"Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.ICo. Type is an interface or abstract class and cannot be instantiated. Path 'co.Name', line 1, position 14.",
|
||||
() =>
|
||||
{
|
||||
InterfacePropertyTestClass testFromDe = (InterfacePropertyTestClass)JsonConvert.DeserializeObject(strFromTest, typeof(InterfacePropertyTestClass));
|
||||
@@ -7162,6 +7162,23 @@ Parameter name: value",
|
||||
}", json);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void RoundtripOfDateTimeOffset()
|
||||
{
|
||||
var content = @"{""startDateTime"":""2012-07-19T14:30:00+09:30""}";
|
||||
|
||||
var jsonSerializerSettings = new JsonSerializerSettings() {DateFormatHandling = DateFormatHandling.IsoDateFormat, DateParseHandling = DateParseHandling.DateTimeOffset, DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind};
|
||||
|
||||
var obj = (JObject)JsonConvert.DeserializeObject(content, jsonSerializerSettings);
|
||||
|
||||
var dateTimeOffset = (DateTimeOffset)((JValue) obj["startDateTime"]).Value;
|
||||
|
||||
Assert.AreEqual(TimeSpan.FromHours(9.5), dateTimeOffset.Offset);
|
||||
Assert.AreEqual("07/19/2012 14:30:00 +09:30", dateTimeOffset.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace Newtonsoft.Json
|
||||
/// Ignore members where the member value is the same as the member's default value when serializing objects
|
||||
/// so that is is not written to JSON.
|
||||
/// This option will ignore all default values (e.g. <c>null</c> for objects and nullable typesl; <c>0</c> for integers,
|
||||
/// decimals and floating point numbers; and <c>false</c> for booleans). The default value ignored can be override by
|
||||
/// the <see cref="DefaultValueAttribute"/>.
|
||||
/// decimals and floating point numbers; and <c>false</c> for booleans). The default value ignored can be changed by
|
||||
/// placing the <see cref="DefaultValueAttribute"/> on the property.
|
||||
/// </summary>
|
||||
Ignore = 1,
|
||||
/// <summary>
|
||||
|
||||
@@ -530,7 +530,7 @@ namespace Newtonsoft.Json
|
||||
reader.DateTimeZoneHandling = _dateTimeZoneHandling.Value;
|
||||
}
|
||||
DateParseHandling? previousDateParseHandling = null;
|
||||
if (_dateParseHandling != null && reader.DateTimeZoneHandling != _dateTimeZoneHandling)
|
||||
if (_dateParseHandling != null && reader.DateParseHandling != _dateParseHandling)
|
||||
{
|
||||
previousDateParseHandling = reader.DateParseHandling;
|
||||
reader.DateParseHandling = _dateParseHandling.Value;
|
||||
|
||||
@@ -432,13 +432,22 @@ namespace Newtonsoft.Json
|
||||
WritePropertyName(reader.Value.ToString());
|
||||
break;
|
||||
case JsonToken.Comment:
|
||||
WriteComment(reader.Value.ToString());
|
||||
WriteComment((reader.Value != null) ? reader.Value.ToString() : null);
|
||||
break;
|
||||
case JsonToken.Integer:
|
||||
WriteValue(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case JsonToken.Float:
|
||||
WriteValue(Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture));
|
||||
object value = reader.Value;
|
||||
|
||||
if (value is decimal)
|
||||
WriteValue((decimal)value);
|
||||
else if (value is double)
|
||||
WriteValue((double)value);
|
||||
else if (value is float)
|
||||
WriteValue((float)value);
|
||||
else
|
||||
WriteValue(Convert.ToDouble(value, CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case JsonToken.String:
|
||||
WriteValue(reader.Value.ToString());
|
||||
@@ -462,10 +471,15 @@ namespace Newtonsoft.Json
|
||||
WriteEndConstructor();
|
||||
break;
|
||||
case JsonToken.Date:
|
||||
WriteValue((DateTime)reader.Value);
|
||||
#if !PocketPC && !NET20
|
||||
if (reader.Value is DateTimeOffset)
|
||||
WriteValue((DateTimeOffset)reader.Value);
|
||||
else
|
||||
#endif
|
||||
WriteValue(Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture));
|
||||
break;
|
||||
case JsonToken.Raw:
|
||||
WriteRawValue((string)reader.Value);
|
||||
WriteRawValue((reader.Value != null) ? reader.Value.ToString() : null);
|
||||
break;
|
||||
case JsonToken.Bytes:
|
||||
WriteValue((byte[])reader.Value);
|
||||
|
||||
@@ -90,7 +90,7 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("4.5.9.15324")]
|
||||
[assembly: AssemblyFileVersion("4.5.9.15402")]
|
||||
#endif
|
||||
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
@@ -432,7 +432,10 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
foreach (ParameterInfo parameterInfo in constructorParameters)
|
||||
{
|
||||
JsonProperty matchingMemberProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name);
|
||||
// it is possible to generate a ParameterInfo with a null name using Reflection.Emit
|
||||
// protect against an ArgumentNullException from GetClosestMatchProperty by testing for null here
|
||||
JsonProperty matchingMemberProperty = (parameterInfo.Name != null) ? memberProperties.GetClosestMatchProperty(parameterInfo.Name) : null;
|
||||
|
||||
// type must match as well as name
|
||||
if (matchingMemberProperty != null && matchingMemberProperty.PropertyType != parameterInfo.ParameterType)
|
||||
matchingMemberProperty = null;
|
||||
|
||||
@@ -1165,7 +1165,7 @@ To fix this error either change the environment to be fully trusted, change the
|
||||
IDynamicMetaObjectProvider newObject;
|
||||
|
||||
if (contract.UnderlyingType.IsInterface() || contract.UnderlyingType.IsAbstract())
|
||||
throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantated.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
|
||||
throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
|
||||
|
||||
if (contract.DefaultCreator != null &&
|
||||
(!contract.DefaultCreatorNonPublic || Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
|
||||
@@ -1446,7 +1446,7 @@ To fix this error either change the environment to be fully trusted, change the
|
||||
object newObject = null;
|
||||
|
||||
if (objectContract.UnderlyingType.IsInterface() || objectContract.UnderlyingType.IsAbstract())
|
||||
throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantated.".FormatWith(CultureInfo.InvariantCulture, objectContract.UnderlyingType));
|
||||
throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.".FormatWith(CultureInfo.InvariantCulture, objectContract.UnderlyingType));
|
||||
|
||||
if (objectContract.OverrideConstructor != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user