diff --git a/Build/Newtonsoft.Json.nuspec b/Build/Newtonsoft.Json.nuspec
index 0b1eadb9..e5418d7b 100644
--- a/Build/Newtonsoft.Json.nuspec
+++ b/Build/Newtonsoft.Json.nuspec
@@ -19,29 +19,29 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Build/build.ps1 b/Build/build.ps1
index cca9deb4..5eb648a8 100644
--- a/Build/build.ps1
+++ b/Build/build.ps1
@@ -2,7 +2,7 @@
$zipFileName = "Json90r1.zip"
$majorVersion = "9.0"
$majorWithReleaseVersion = "9.0.1"
- $nugetPrerelease = "beta1"
+ $nugetPrerelease = $null
$version = GetVersion $majorWithReleaseVersion
$packageId = "Newtonsoft.Json"
$signAssemblies = $false
@@ -11,7 +11,7 @@
$buildNuGet = $true
$treatWarningsAsErrors = $false
$workingName = if ($workingName) {$workingName} else {"Working"}
- $netCliVersion = "1.0.0-preview1-002702"
+ $netCliVersion = "1.0.0-preview3-003171"
$baseDir = resolve-path ..
$buildDir = "$baseDir\Build"
@@ -53,8 +53,7 @@ task Clean {
}
# Build each solution, optionally signed
-task Build -depends Clean {
-
+task Build -depends Clean {
Write-Host "Copying source to working source directory $workingSourceDir"
robocopy $sourceDir $workingSourceDir /MIR /NP /XD bin obj TestResults AppPackages $packageDirs .vs artifacts /XF *.suo *.user *.lock.json | Out-Default
@@ -206,7 +205,7 @@ function NetCliBuild($build)
$name = $build.Name
$projectPath = "$workingSourceDir\Newtonsoft.Json\project.json"
- exec { .\Tools\Dotnet\install.ps1 -Version $netCliVersion | Out-Default }
+ exec { .\Tools\Dotnet\dotnet-install.ps1 -Version $netCliVersion | Out-Default }
exec { dotnet --version | Out-Default }
Write-Host -ForegroundColor Green "Restoring packages for $name"
@@ -221,7 +220,7 @@ function NetCliTests($build)
{
$name = $build.TestsName
- exec { .\Tools\Dotnet\install.ps1 -Version $netCliVersion | Out-Default }
+ exec { .\Tools\Dotnet\dotnet-install.ps1 -Version $netCliVersion | Out-Default }
exec { dotnet --version | Out-Default }
Write-Host -ForegroundColor Green "Restoring packages for $name"
diff --git a/Doc/Samples/Serializer/NamingStrategyAttributes.aml b/Doc/Samples/Serializer/NamingStrategyAttributes.aml
new file mode 100644
index 00000000..4701cf9f
--- /dev/null
+++ b/Doc/Samples/Serializer/NamingStrategyAttributes.aml
@@ -0,0 +1,16 @@
+
+
+
+
+ This sample uses T:Newtonsoft.Json.Serialization.NamingStrategy
+ types specified on attributes to control serialized property names.
+
+
+ Sample
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Doc/Samples/Serializer/NamingStrategyCamelCase.aml b/Doc/Samples/Serializer/NamingStrategyCamelCase.aml
new file mode 100644
index 00000000..b40e00a9
--- /dev/null
+++ b/Doc/Samples/Serializer/NamingStrategyCamelCase.aml
@@ -0,0 +1,16 @@
+
+
+
+
+ This sample uses a T:Newtonsoft.Json.Serialization.CamelCaseNamingStrategy
+ specified using a contract resolver to camel case serialized property names.
+
+
+ Sample
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Doc/Samples/Serializer/NamingStrategySkipDictionaryKeys.aml b/Doc/Samples/Serializer/NamingStrategySkipDictionaryKeys.aml
new file mode 100644
index 00000000..4aae69e5
--- /dev/null
+++ b/Doc/Samples/Serializer/NamingStrategySkipDictionaryKeys.aml
@@ -0,0 +1,16 @@
+
+
+
+
+ This sample configures a T:Newtonsoft.Json.Serialization.CamelCaseNamingStrategy
+ to not camel case dictionary keys.
+
+
+ Sample
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Doc/Samples/Serializer/NamingStrategySkipSpecifiedNames.aml b/Doc/Samples/Serializer/NamingStrategySkipSpecifiedNames.aml
new file mode 100644
index 00000000..7f7eebc1
--- /dev/null
+++ b/Doc/Samples/Serializer/NamingStrategySkipSpecifiedNames.aml
@@ -0,0 +1,16 @@
+
+
+
+
+ This sample configures a T:Newtonsoft.Json.Serialization.CamelCaseNamingStrategy
+ to not camel case properties that already have a name specified with an attribute.
+
+
+ Sample
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Doc/Samples/Serializer/NamingStrategySnakeCase.aml b/Doc/Samples/Serializer/NamingStrategySnakeCase.aml
new file mode 100644
index 00000000..39a5dcbf
--- /dev/null
+++ b/Doc/Samples/Serializer/NamingStrategySnakeCase.aml
@@ -0,0 +1,16 @@
+
+
+
+
+ This sample uses a T:Newtonsoft.Json.Serialization.SnakeCaseNamingStrategy
+ specified using a contract resolver to snake case serialized property names.
+
+
+ Sample
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Doc/SerializationAttributes.aml b/Doc/SerializationAttributes.aml
index 3fe7ed53..8b313f91 100644
--- a/Doc/SerializationAttributes.aml
+++ b/Doc/SerializationAttributes.aml
@@ -48,6 +48,8 @@
(a member must have the JsonProperty or DataMember attribute to be serialized), opt-out (everything is
serialized by default but can be ignored with the JsonIgnoreAttribute, Json.NET's default behavior) or
fields (all public and private fields are serialized and properties are ignored).
+ The NamingStrategy setting on this attributes can be set to a T:Newtonsoft.Json.Serialization.NamingStrategy
+ type that specifies how property names are serialized.Json.NET serializes .NET classes that implement IEnumerable as a JSON array populated with the
IEnumerable values. Placing the T:Newtonsoft.Json.JsonObjectAttribute
overrides this behavior and forces the serializer to serialize the class's fields and properties.
@@ -77,6 +79,7 @@
JsonPropertyAttribute indicates that a property should be serialized when member serialization is set to opt-in.It includes non-public properties in serialization and deserialization.It can be used to customize type name, reference, null, and default value handling for the property value.
+ It can be used to customize the T:Newtonsoft.Json.Serialization.NamingStrategy of the serialized property name.It can be used to customize the property's collection items JsonConverter, type name handling, and reference handling.
diff --git a/Doc/doc.content b/Doc/doc.content
index 7524c2c7..10cc9241 100644
--- a/Doc/doc.content
+++ b/Doc/doc.content
@@ -30,7 +30,7 @@
-
+
@@ -72,6 +72,7 @@
+
@@ -90,8 +91,12 @@
+
+
+
+
-
+
@@ -110,7 +115,7 @@
-
+
@@ -152,7 +157,7 @@
-
+
diff --git a/Doc/doc.shfbproj b/Doc/doc.shfbproj
index 8263bced..e6dc4eea 100644
--- a/Doc/doc.shfbproj
+++ b/Doc/doc.shfbproj
@@ -8,7 +8,7 @@
AnyCPU2.0{fd19f68e-72c8-4576-9775-b4480b0db686}
- 1.9.9.0
+ 2015.6.5.0Documentation
@@ -100,6 +100,11 @@
+
+
+
+
+
diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategyAttributes.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategyAttributes.cs
new file mode 100644
index 00000000..32beb5f6
--- /dev/null
+++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategyAttributes.cs
@@ -0,0 +1,83 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
+#if DNXCORE50
+using Xunit;
+using Test = Xunit.FactAttribute;
+using Assert = Newtonsoft.Json.Tests.XUnitAssert;
+#else
+using NUnit.Framework;
+#endif
+
+namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
+{
+ [TestFixture]
+ public class NamingStrategyAttributes : TestFixtureBase
+ {
+ #region Types
+ [JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
+ public class User
+ {
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ [JsonProperty(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
+ public int SnakeRating { get; set; }
+ }
+ #endregion
+
+ [Test]
+ public void Example()
+ {
+ #region Usage
+ User user = new User
+ {
+ FirstName = "Tom",
+ LastName = "Riddle",
+ SnakeRating = 10
+ };
+
+ string json = JsonConvert.SerializeObject(user, Formatting.Indented);
+
+ Console.WriteLine(json);
+ // {
+ // "firstName": "Tom",
+ // "lastName": "Riddle",
+ // "snake_rating": 10
+ // }
+ #endregion
+
+ StringAssert.AreEqual(@"{
+ ""firstName"": ""Tom"",
+ ""lastName"": ""Riddle"",
+ ""snake_rating"": 10
+}", json);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategyCamelCase.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategyCamelCase.cs
new file mode 100644
index 00000000..9a6b000d
--- /dev/null
+++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategyCamelCase.cs
@@ -0,0 +1,86 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
+#if DNXCORE50
+using Xunit;
+using Test = Xunit.FactAttribute;
+using Assert = Newtonsoft.Json.Tests.XUnitAssert;
+#else
+using NUnit.Framework;
+#endif
+
+namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
+{
+ [TestFixture]
+ public class NamingStrategyCamelCase : TestFixtureBase
+ {
+ #region Types
+ public class User
+ {
+ public string UserName { get; set; }
+ public bool Enabled { get; set; }
+ }
+ #endregion
+
+ [Test]
+ public void Example()
+ {
+ #region Usage
+ User user1 = new User
+ {
+ UserName = "jamesn",
+ Enabled = true
+ };
+
+ DefaultContractResolver contractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy()
+ };
+
+ string json = JsonConvert.SerializeObject(user1, new JsonSerializerSettings
+ {
+ ContractResolver = contractResolver,
+ Formatting = Formatting.Indented
+ });
+
+ Console.WriteLine(json);
+ // {
+ // "userName": "jamesn",
+ // "enabled": true
+ // }
+ #endregion
+
+ StringAssert.AreEqual(@"{
+ ""userName"": ""jamesn"",
+ ""enabled"": true
+}", json);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySkipDictionaryKeys.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySkipDictionaryKeys.cs
new file mode 100644
index 00000000..48e9a1c8
--- /dev/null
+++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySkipDictionaryKeys.cs
@@ -0,0 +1,106 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
+#if DNXCORE50
+using Xunit;
+using Test = Xunit.FactAttribute;
+using Assert = Newtonsoft.Json.Tests.XUnitAssert;
+#else
+using NUnit.Framework;
+#endif
+
+namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
+{
+ [TestFixture]
+ public class NamingStrategySkipDictionaryKeys : TestFixtureBase
+ {
+ #region Types
+ public class DailyHighScores
+ {
+ public DateTime Date { get; set; }
+ public string Game { get; set; }
+ public Dictionary UserPoints { get; set; }
+ }
+ #endregion
+
+ [Test]
+ public void Example()
+ {
+ #region Usage
+ DailyHighScores dailyHighScores = new DailyHighScores
+ {
+ Date = new DateTime(2016, 6, 27, 0, 0, 0, DateTimeKind.Utc),
+ Game = "Donkey Kong",
+ UserPoints = new Dictionary
+ {
+ ["JamesNK"] = 9001,
+ ["JoC"] = 1337,
+ ["JessicN"] = 1000
+ }
+ };
+
+ DefaultContractResolver contractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy
+ {
+ ProcessDictionaryKeys = false
+ }
+ };
+
+ string json = JsonConvert.SerializeObject(dailyHighScores, new JsonSerializerSettings
+ {
+ ContractResolver = contractResolver,
+ Formatting = Formatting.Indented
+ });
+
+ Console.WriteLine(json);
+ // {
+ // "date": "2016-06-27T00:00:00Z",
+ // "game": "Donkey Kong",
+ // "userPoints": {
+ // "JamesNK": 9001,
+ // "JoC": 1337,
+ // "JessicN": 1000
+ // }
+ // }
+ #endregion
+
+ StringAssert.AreEqual(@"{
+ ""date"": ""2016-06-27T00:00:00Z"",
+ ""game"": ""Donkey Kong"",
+ ""userPoints"": {
+ ""JamesNK"": 9001,
+ ""JoC"": 1337,
+ ""JessicN"": 1000
+ }
+}", json);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySkipSpecifiedNames.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySkipSpecifiedNames.cs
new file mode 100644
index 00000000..72edcaff
--- /dev/null
+++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySkipSpecifiedNames.cs
@@ -0,0 +1,94 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
+#if DNXCORE50
+using Xunit;
+using Test = Xunit.FactAttribute;
+using Assert = Newtonsoft.Json.Tests.XUnitAssert;
+#else
+using NUnit.Framework;
+#endif
+
+namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
+{
+ [TestFixture]
+ public class NamingStrategySkipSpecifiedNames : TestFixtureBase
+ {
+ #region Types
+ public class User
+ {
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ [JsonProperty(PropertyName = "UPN")]
+ public string Upn { get; set; }
+ }
+ #endregion
+
+ [Test]
+ public void Example()
+ {
+ #region Usage
+ User user = new User
+ {
+ FirstName = "John",
+ LastName = "Smith",
+ Upn = "john.smith@acme.com"
+ };
+
+ DefaultContractResolver contractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy
+ {
+ OverrideSpecifiedNames = false
+ }
+ };
+
+ string json = JsonConvert.SerializeObject(user, new JsonSerializerSettings
+ {
+ ContractResolver = contractResolver,
+ Formatting = Formatting.Indented
+ });
+
+ Console.WriteLine(json);
+ // {
+ // "firstName": "John",
+ // "lastName": "Smith",
+ // "UPN": "john.smith@acme.com"
+ // }
+ #endregion
+
+ StringAssert.AreEqual(@"{
+ ""firstName"": ""John"",
+ ""lastName"": ""Smith"",
+ ""UPN"": ""john.smith@acme.com""
+}", json);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySnakeCase.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySnakeCase.cs
new file mode 100644
index 00000000..b16caf7b
--- /dev/null
+++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/NamingStrategySnakeCase.cs
@@ -0,0 +1,86 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
+#if DNXCORE50
+using Xunit;
+using Test = Xunit.FactAttribute;
+using Assert = Newtonsoft.Json.Tests.XUnitAssert;
+#else
+using NUnit.Framework;
+#endif
+
+namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
+{
+ [TestFixture]
+ public class NamingStrategySnakeCase : TestFixtureBase
+ {
+ #region Types
+ public class User
+ {
+ public string UserName { get; set; }
+ public bool Enabled { get; set; }
+ }
+ #endregion
+
+ [Test]
+ public void Example()
+ {
+ #region Usage
+ User user1 = new User
+ {
+ UserName = "jamesn",
+ Enabled = true
+ };
+
+ DefaultContractResolver contractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new SnakeCaseNamingStrategy()
+ };
+
+ string json = JsonConvert.SerializeObject(user1, new JsonSerializerSettings
+ {
+ ContractResolver = contractResolver,
+ Formatting = Formatting.Indented
+ });
+
+ Console.WriteLine(json);
+ // {
+ // "user_name": "jamesn",
+ // "enabled": true
+ // }
+ #endregion
+
+ StringAssert.AreEqual(@"{
+ ""user_name"": ""jamesn"",
+ ""enabled"": true
+}", json);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
index 5eb93ab5..1ae55cff 100644
--- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
+++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
@@ -157,6 +157,10 @@
+
+
+
+
@@ -205,6 +209,7 @@
+
diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json
index ffdaaa2c..f9804862 100644
--- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json
+++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.project.json
@@ -1,9 +1,9 @@
{
"dependencies": {
- "Autofac": "4.0.0-beta7-130",
+ "Autofac": "4.0.0-rc2-240",
"FSharp.Core": "4.0.0.1",
"NUnit": "2.6.2",
- "System.Buffers": "4.0.0-rc2-24027",
+ "System.Buffers": "4.0.0",
"System.Collections.Immutable": "1.1.37"
},
"frameworks": {
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs
index b71149ea..b0c481b8 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs
@@ -41,7 +41,9 @@ using System.Linq;
#endif
using System.Text;
using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
+using Newtonsoft.Json.Utilities;
#if NETFX_CORE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
@@ -1561,7 +1563,7 @@ namespace Newtonsoft.Json.Tests.Serialization
});
StringAssert.AreEqual(@"{
- ""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.TestObjects.Event1[,], Newtonsoft.Json.Tests]], mscorlib"",
+ ""$type"": """ + ReflectionUtils.GetTypeName(typeof(List), 0, DefaultSerializationBinder.Instance) + @""",
""$values"": [
{
""$type"": ""Newtonsoft.Json.Tests.TestObjects.Event1[,], Newtonsoft.Json.Tests"",
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
index 53fc1fa1..2d2d9797 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
@@ -7234,7 +7234,7 @@ Path '', line 1, position 1.");
""Longitude"": -117.766684,
""TimeStamp"": ""2000-03-01T23:59:59Z"",
""Payload"": {
- ""$type"": ""System.Byte[], mscorlib"",
+ ""$type"": """ + ReflectionUtils.GetTypeName(typeof(byte[]), 0, DefaultSerializationBinder.Instance) + @""",
""$value"": ""AAECAwQFBgcICQ==""
}
}", jsonString);
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs
index 08c3c6b8..b615a355 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/MetadataPropertyHandlingTests.cs
@@ -28,6 +28,7 @@ using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.Text;
using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
#if NETFX_CORE
@@ -133,7 +134,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string serializedString = JsonConvert.SerializeObject(inputContext, jsonSerializerSettings);
StringAssert.AreEqual(@"{
- ""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Guid, mscorlib]], mscorlib"",
+ ""$type"": """ + ReflectionUtils.GetTypeName(typeof(Dictionary), 0, DefaultSerializationBinder.Instance) + @""",
""k1"": ""5dd2dba0-20c0-49f8-a054-1fa3b0a8d774""
}", serializedString);
@@ -165,7 +166,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""Longitude"": -117.766684,
""TimeStamp"": ""2000-03-01T23:59:59Z"",
""Payload"": {
- ""$type"": ""System.Byte[], mscorlib"",
+ ""$type"": """ + ReflectionUtils.GetTypeName(typeof(byte[]), 0, DefaultSerializationBinder.Instance) + @""",
""$value"": ""AAECAwQFBgcICQ==""
}
}", jsonString);
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs
index 05e60f04..3ea9915d 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/PreserveReferencesHandlingTests.cs
@@ -29,7 +29,9 @@ using System.IO;
using System.Runtime.Serialization.Formatters;
using System.Text;
using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
+using Newtonsoft.Json.Utilities;
#if NETFX_CORE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
@@ -116,7 +118,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""$type"": ""Newtonsoft.Json.Tests.Serialization.PreserveReferencesHandlingTests+Container, Newtonsoft.Json.Tests"",
""ListA"": {
""$id"": ""2"",
- ""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.Serialization.PreserveReferencesHandlingTests+ContentA, Newtonsoft.Json.Tests]], mscorlib"",
+ ""$type"": """ + ReflectionUtils.GetTypeName(typeof(List), 0, DefaultSerializationBinder.Instance) + @""",
""$values"": [
{
""$id"": ""3"",
@@ -127,7 +129,7 @@ namespace Newtonsoft.Json.Tests.Serialization
},
""ListB"": {
""$id"": ""4"",
- ""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.Serialization.PreserveReferencesHandlingTests+ContentA, Newtonsoft.Json.Tests]], mscorlib"",
+ ""$type"": """ + ReflectionUtils.GetTypeName(typeof(List), 0, DefaultSerializationBinder.Instance) + @""",
""$values"": [
{
""$ref"": ""3""
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TraceWriterTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TraceWriterTests.cs
index e931c634..8dcaad3d 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/TraceWriterTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/TraceWriterTests.cs
@@ -24,6 +24,7 @@ using NUnit.Framework;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
+using Newtonsoft.Json.Utilities;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
@@ -551,12 +552,12 @@ Newtonsoft.Json Error: 0 : Error!
});
Assert.AreEqual("Started serializing System.Collections.Generic.List`1[System.Object]. Path ''.", traceWriter.TraceRecords[0].Message);
- Assert.AreEqual("Writing type name 'System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib' for System.Collections.Generic.List`1[System.Object]. Path ''.", traceWriter.TraceRecords[1].Message);
+ Assert.AreEqual("Writing type name '" + ReflectionUtils.GetTypeName(typeof(List