-Increment version to 5.0.7

-Added default value and required support to constructor deserialization
This commit is contained in:
James Newton-King
2013-10-11 20:43:07 +13:00
parent 14a2b3aca8
commit f304f7215f
7 changed files with 84 additions and 13 deletions
+3 -3
View File
@@ -2,13 +2,13 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Newtonsoft.Json</id>
<version>5.0.6</version>
<version>5.0.7</version>
<title>Json.NET</title>
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
<authors>James Newton-King</authors>
<language>en-US</language>
<projectUrl>http://james.newtonking.com/projects/json-net.aspx</projectUrl>
<licenseUrl>http://json.codeplex.com/license</licenseUrl>
<projectUrl>http://james.newtonking.com/json</projectUrl>
<licenseUrl>https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md</licenseUrl>
<tags>json</tags>
</metadata>
</package>
+6 -7
View File
@@ -1,7 +1,7 @@
properties {
$zipFileName = "Json50r6.zip"
$zipFileName = "Json50r7.zip"
$majorVersion = "4.5"
$majorWithReleaseVersion = "5.0.6"
$majorWithReleaseVersion = "5.0.7"
$version = GetVersion $majorWithReleaseVersion
$signAssemblies = $false
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
@@ -76,12 +76,11 @@ task Package -depends Build {
if ($buildNuGet)
{
New-Item -Path $workingDir\NuGet -ItemType Directory
#New-Item -Path $workingDir\NuGet\tools -ItemType Directory
New-Item -Path $workingDir\NuGet -ItemType Directory
Copy-Item -Path "$buildDir\Newtonsoft.Json.nuspec" -Destination $workingDir\NuGet\Newtonsoft.Json.nuspec -recurse
#Copy-Item -Path "$buildDir\install.ps1" -Destination $workingDir\NuGet\tools\install.ps1 -recurse
New-Item -Path $workingDir\NuGet\tools -ItemType Directory
Copy-Item -Path "$buildDir\install.ps1" -Destination $workingDir\NuGet\tools\install.ps1 -recurse
foreach ($build in $builds)
{
+1 -1
View File
@@ -5,7 +5,7 @@ param($installPath, $toolsPath, $package, $project)
try
{
$url = "http://www.json.net"
$url = "http://james.newtonking.com/json"
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
@@ -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.6.16606")]
[assembly: AssemblyFileVersion("5.0.7.16611")]
@@ -24,6 +24,7 @@
#endregion
using System;
using System.ComponentModel;
#if !(NET35 || NET20 || SILVERLIGHT)
using System.Collections.Concurrent;
#endif
@@ -2468,6 +2469,62 @@ keyword such as type of business.""
Assert.AreEqual("lastName", o.lastName);
}
public sealed class ConstructorAndDefaultValueAttributeTestClass
{
public ConstructorAndDefaultValueAttributeTestClass(string testProperty1)
{
this.TestProperty1 = testProperty1;
}
public string TestProperty1 { get; set; }
[DefaultValue(21)]
public int TestProperty2 { get; set; }
}
[Test]
public void PopulateDefaultValueWhenUsingConstructor()
{
string json = "{ 'testProperty1': 'value' }";
ConstructorAndDefaultValueAttributeTestClass c = JsonConvert.DeserializeObject<ConstructorAndDefaultValueAttributeTestClass>(json, new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Populate
});
Assert.AreEqual("value", c.TestProperty1);
Assert.AreEqual(21, c.TestProperty2);
c = JsonConvert.DeserializeObject<ConstructorAndDefaultValueAttributeTestClass>(json, new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
});
Assert.AreEqual("value", c.TestProperty1);
Assert.AreEqual(21, c.TestProperty2);
}
public sealed class ConstructorAndRequiredTestClass
{
public ConstructorAndRequiredTestClass(string testProperty1)
{
this.TestProperty1 = testProperty1;
}
public string TestProperty1 { get; set; }
[JsonProperty(Required = Required.AllowNull)]
public int TestProperty2 { get; set; }
}
[Test]
public void RequiredWhenUsingConstructor()
{
string json = "{ 'testProperty1': 'value' }";
ExceptionAssert.Throws<JsonSerializationException>("Required property 'TestProperty2' not found in JSON. Path '', line 1, position 28.",
() => JsonConvert.DeserializeObject<ConstructorAndRequiredTestClass>(json));
}
[Test]
public void DeserializePropertiesOnToNonDefaultConstructor()
{
@@ -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.6.16606")]
[assembly: AssemblyFileVersion("5.0.7.16611")]
[assembly: CLSCompliant(true)]
@@ -1444,6 +1444,11 @@ To fix this error either change the environment to be fully trusted, change the
{
ValidationUtils.ArgumentNotNull(constructorInfo, "constructorInfo");
// only need to keep a track of properies presence if they are required or a value should be defaulted if missing
Dictionary<JsonProperty, PropertyPresence> propertiesPresence = (contract.HasRequiredOrDefaultValueProperties || HasFlag(Serializer._defaultValueHandling, DefaultValueHandling.Populate))
? contract.Properties.ToDictionary(m => m, m => PropertyPresence.None)
: null;
Type objectType = contract.UnderlyingType;
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
@@ -1461,6 +1466,14 @@ To fix this error either change the environment to be fully trusted, change the
constructorParameters[matchingConstructorParameter] = propertyValue.Value;
else
remainingPropertyValues.Add(propertyValue);
if (propertiesPresence != null)
{
// map from constructor property to normal property
var property = propertiesPresence.Keys.FirstOrDefault(p => p.PropertyName == propertyValue.Key.PropertyName);
if (property != null)
propertiesPresence[property] = (propertyValue.Value == null) ? PropertyPresence.Null : PropertyPresence.Value;
}
}
object createdObject = constructorInfo.Invoke(constructorParameters.Values.ToArray());
@@ -1520,6 +1533,8 @@ To fix this error either change the environment to be fully trusted, change the
}
}
EndObject(createdObject, reader, contract, reader.Depth, propertiesPresence);
OnDeserialized(reader, contract, createdObject);
return createdObject;
}