-Increment version to 5.0.7
-Added default value and required support to constructor deserialization
This commit is contained in:
@@ -2,13 +2,13 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Newtonsoft.Json</id>
|
<id>Newtonsoft.Json</id>
|
||||||
<version>5.0.6</version>
|
<version>5.0.7</version>
|
||||||
<title>Json.NET</title>
|
<title>Json.NET</title>
|
||||||
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
|
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
|
||||||
<authors>James Newton-King</authors>
|
<authors>James Newton-King</authors>
|
||||||
<language>en-US</language>
|
<language>en-US</language>
|
||||||
<projectUrl>http://james.newtonking.com/projects/json-net.aspx</projectUrl>
|
<projectUrl>http://james.newtonking.com/json</projectUrl>
|
||||||
<licenseUrl>http://json.codeplex.com/license</licenseUrl>
|
<licenseUrl>https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md</licenseUrl>
|
||||||
<tags>json</tags>
|
<tags>json</tags>
|
||||||
</metadata>
|
</metadata>
|
||||||
</package>
|
</package>
|
||||||
+4
-5
@@ -1,7 +1,7 @@
|
|||||||
properties {
|
properties {
|
||||||
$zipFileName = "Json50r6.zip"
|
$zipFileName = "Json50r7.zip"
|
||||||
$majorVersion = "4.5"
|
$majorVersion = "4.5"
|
||||||
$majorWithReleaseVersion = "5.0.6"
|
$majorWithReleaseVersion = "5.0.7"
|
||||||
$version = GetVersion $majorWithReleaseVersion
|
$version = GetVersion $majorWithReleaseVersion
|
||||||
$signAssemblies = $false
|
$signAssemblies = $false
|
||||||
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
|
$signKeyPath = "D:\Development\Releases\newtonsoft.snk"
|
||||||
@@ -77,11 +77,10 @@ task Package -depends Build {
|
|||||||
if ($buildNuGet)
|
if ($buildNuGet)
|
||||||
{
|
{
|
||||||
New-Item -Path $workingDir\NuGet -ItemType Directory
|
New-Item -Path $workingDir\NuGet -ItemType Directory
|
||||||
#New-Item -Path $workingDir\NuGet\tools -ItemType Directory
|
|
||||||
|
|
||||||
Copy-Item -Path "$buildDir\Newtonsoft.Json.nuspec" -Destination $workingDir\NuGet\Newtonsoft.Json.nuspec -recurse
|
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)
|
foreach ($build in $builds)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ param($installPath, $toolsPath, $package, $project)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$url = "http://www.json.net"
|
$url = "http://james.newtonking.com/json"
|
||||||
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
|
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
|
||||||
|
|
||||||
if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
|
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
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("5.0.6.16606")]
|
[assembly: AssemblyFileVersion("5.0.7.16611")]
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
#if !(NET35 || NET20 || SILVERLIGHT)
|
#if !(NET35 || NET20 || SILVERLIGHT)
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
#endif
|
#endif
|
||||||
@@ -2468,6 +2469,62 @@ keyword such as type of business.""
|
|||||||
Assert.AreEqual("lastName", o.lastName);
|
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]
|
[Test]
|
||||||
public void DeserializePropertiesOnToNonDefaultConstructor()
|
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
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("5.0.6.16606")]
|
[assembly: AssemblyFileVersion("5.0.7.16611")]
|
||||||
|
|
||||||
[assembly: CLSCompliant(true)]
|
[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");
|
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;
|
Type objectType = contract.UnderlyingType;
|
||||||
|
|
||||||
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
|
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;
|
constructorParameters[matchingConstructorParameter] = propertyValue.Value;
|
||||||
else
|
else
|
||||||
remainingPropertyValues.Add(propertyValue);
|
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());
|
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);
|
OnDeserialized(reader, contract, createdObject);
|
||||||
return createdObject;
|
return createdObject;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user