diff --git a/lib/newtonsoft.json/Newtonsoft.Json.dll b/lib/newtonsoft.json/Newtonsoft.Json.dll
index c07a3b2e4..81639f9b1 100644
Binary files a/lib/newtonsoft.json/Newtonsoft.Json.dll and b/lib/newtonsoft.json/Newtonsoft.Json.dll differ
diff --git a/lib/newtonsoft.json/Newtonsoft.Json.xml b/lib/newtonsoft.json/Newtonsoft.Json.xml
index 52d6762be..d2a7e8e75 100644
--- a/lib/newtonsoft.json/Newtonsoft.Json.xml
+++ b/lib/newtonsoft.json/Newtonsoft.Json.xml
@@ -735,7 +735,12 @@
- Get or set how time zones are handling when writing JSON.
+ Get or set how time zones are handling when writing JSON text.
+
+
+
+
+ Get or set how strings are escaped when writing JSON text.
@@ -1640,6 +1645,50 @@
Instructs the to use the specified constructor when deserializing that object.
+
+
+ Represents a trace writer that writes to the application's instances.
+
+
+
+
+ Represents a trace writer.
+
+
+
+
+ Writes the specified trace level, message and optional exception.
+
+ The at which to write this trace.
+ The trace message.
+ The trace exception. This parameter is optional.
+
+
+
+ Gets the that will be used to filter the trace messages passed to the writer.
+ For example a filter level of Info
will exclude Verbose
messages and include Info
,
+ Warning
and Error
messages.
+
+ The that will be used to filter the trace messages passed to the writer.
+
+
+
+ Writes the specified trace level, message and optional exception.
+
+ The at which to write this trace.
+ The trace message.
+ The trace exception. This parameter is optional.
+
+
+
+ Gets the that will be used to filter the trace messages passed to the writer.
+ For example a filter level of Info
will exclude Verbose
messages and include Info
,
+ Warning
and Error
messages.
+
+
+ The that will be used to filter the trace messages passed to the writer.
+
+
Contract details for a used by the .
@@ -1746,6 +1795,69 @@
The type name handling.
+
+
+ Represents a trace writer that writes to memory. When the trace message limit is
+ reached then old trace messages will be removed as new messages are added.
+
+
+
+
+ Initializes a new instance of the class.
+
+
+
+
+ Writes the specified trace level, message and optional exception.
+
+ The at which to write this trace.
+ The trace message.
+ The trace exception. This parameter is optional.
+
+
+
+ Returns an enumeration of the most recent trace messages.
+
+ An enumeration of the most recent trace messages.
+
+
+
+ Returns a of the most recent trace messages.
+
+
+ A of the most recent trace messages.
+
+
+
+
+ Gets the that will be used to filter the trace messages passed to the writer.
+ For example a filter level of Info
will exclude Verbose
messages and include Info
,
+ Warning
and Error
messages.
+
+
+ The that will be used to filter the trace messages passed to the writer.
+
+
+
+
+ Specifies how strings are escaped when writing JSON text.
+
+
+
+
+ Only control characters (e.g. newline) are escaped.
+
+
+
+
+ All non-ASCII and control characters (e.g. newline) are escaped.
+
+
+
+
+ HTML (<, >, &, ', ") and control characters (e.g. newline) are escaped.
+
+
Represents a raw JSON string.
@@ -1954,6 +2066,13 @@
The value.
The result of the conversion.
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
Performs an explicit conversion from to .
@@ -1975,6 +2094,20 @@
The value.
The result of the conversion.
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
Performs an explicit conversion from to .
@@ -1996,6 +2129,13 @@
The value.
The result of the conversion.
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
Performs an explicit conversion from to .
@@ -2080,6 +2220,41 @@
The value.
The result of the conversion.
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
+
+
+ Performs an explicit conversion from to .
+
+ The value.
+ The result of the conversion.
+
Performs an implicit conversion from to .
@@ -2262,6 +2437,41 @@
The value to create a from.
The initialized with the specified value.
+
+
+ Performs an implicit conversion from to .
+
+ The value to create a from.
+ The initialized with the specified value.
+
+
+
+ Performs an implicit conversion from to .
+
+ The value to create a from.
+ The initialized with the specified value.
+
+
+
+ Performs an implicit conversion from to .
+
+ The value to create a from.
+ The initialized with the specified value.
+
+
+
+ Performs an implicit conversion from to .
+
+ The value to create a from.
+ The initialized with the specified value.
+
+
+
+ Performs an implicit conversion from to .
+
+ The value to create a from.
+ The initialized with the specified value.
+
Creates an for this token.
@@ -2290,6 +2500,13 @@
The object type that the token will be deserialized to.
The new object created from the JSON value.
+
+
+ Creates the specified .NET type from the .
+
+ The object type that the token will be deserialized to.
+ The new object created from the JSON value.
+
Creates the specified .NET type from the using the specified .
@@ -2298,6 +2515,14 @@
The that will be used when creating the object.
The new object created from the JSON value.
+
+
+ Creates the specified .NET type from the using the specified .
+
+ The object type that the token will be deserialized to.
+ The that will be used when creating the object.
+ The new object created from the JSON value.
+
Creates a from a .
@@ -2450,6 +2675,12 @@
The value.
+
+
+ Initializes a new instance of the class with the given value.
+
+ The value.
+
Initializes a new instance of the class with the given value.
@@ -3017,7 +3248,10 @@
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, and ignores setting members when the JSON value equals the member's default value.
+ so that is is not written to JSON.
+ This option will ignore all default values (e.g. null for objects and nullable typesl; 0 for integers,
+ decimals and floating point numbers; and false for booleans). The default value ignored can be changed by
+ placing the on the property.
@@ -3167,6 +3401,12 @@
The reference resolver.
+
+
+ Gets or sets the used by the serializer when writing trace messages.
+
+ The trace writer.
+
Gets or sets the used by the serializer when resolving type names.
@@ -4244,7 +4484,7 @@
Converts the to its JSON string representation.
The value to convert.
- The string delimiter character.
+ The string delimiter character.
A JSON string representation of the .
@@ -4743,6 +4983,12 @@
Gets or sets the used by the serializer when resolving type names.
+
+
+ Gets or sets the used by the serializer when writing trace messages.
+
+ The trace writer.
+
Gets or sets how type name writing and reading is handled by the serializer.
@@ -5301,6 +5547,34 @@
A into which this method will write.
A collection of which will be used when writing the token.
+
+
+ Gets the with the specified property name.
+
+ Name of the property.
+ The with the specified property name.
+
+
+
+ Gets the with the specified property name.
+ The exact property name will be searched for first and if no matching property is found then
+ the will be used to match a property.
+
+ Name of the property.
+ One of the enumeration values that specifies how the strings will be compared.
+ The with the specified property name.
+
+
+
+ Tries to get the with the specified property name.
+ The exact property name will be searched for first and if no matching property is found then
+ the will be used to match a property.
+
+ Name of the property.
+ The value.
+ One of the enumeration values that specifies how the strings will be compared.
+ true if a value was successfully retrieved; otherwise, false.
+
Adds the specified property name.
diff --git a/src/Orchard.Tests/Orchard.Framework.Tests.csproj b/src/Orchard.Tests/Orchard.Framework.Tests.csproj
index 738eb2179..1ff295d27 100644
--- a/src/Orchard.Tests/Orchard.Framework.Tests.csproj
+++ b/src/Orchard.Tests/Orchard.Framework.Tests.csproj
@@ -262,6 +262,7 @@
+
diff --git a/src/Orchard.Tests/Services/JsonConverterTests.cs b/src/Orchard.Tests/Services/JsonConverterTests.cs
new file mode 100644
index 000000000..4463bf6c0
--- /dev/null
+++ b/src/Orchard.Tests/Services/JsonConverterTests.cs
@@ -0,0 +1,47 @@
+using System;
+using NUnit.Framework;
+using Newtonsoft.Json.Linq;
+using Orchard.Services;
+
+namespace Orchard.Tests.Services {
+
+ [TestFixture]
+ public class JsonConverterTests {
+ [Test]
+ public void ShouldConvertPrimitiveTypesToJSon() {
+ var converter = new DefaultJsonConverter();
+
+ Assert.That(converter.Serialize(12), Is.EqualTo("12"));
+ Assert.That(converter.Serialize(true), Is.EqualTo("true"));
+ Assert.That(converter.Serialize(12.345), Is.EqualTo("12.345"));
+ Assert.That(converter.Serialize("string"), Is.EqualTo("\"string\""));
+ Assert.That(converter.Serialize(new DateTime(2013, 1, 31, 0, 0, 0, DateTimeKind.Utc)), Is.EqualTo("\"2013-01-31T00:00:00Z\""));
+ }
+
+ [Test]
+ public void ShouldConvertAnonymousTypeToJSon() {
+ dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}");
+
+ Assert.That((int)d.number, Is.EqualTo(1000));
+ Assert.That((int)d["number"], Is.EqualTo(1000));
+ Assert.That((int)d.array.Count, Is.EqualTo(6));
+ }
+
+ [Test]
+ public void ShouldConvertWellKnownTypeToJSon() {
+ var converter = new DefaultJsonConverter();
+ string result = converter.Serialize(new Animal { Age = 12, Name = "Milou" });
+ var o = converter.Deserialize(result);
+
+ Assert.That(o.Age, Is.EqualTo(12));
+ Assert.That(o.Name, Is.EqualTo("Milou"));
+ }
+
+
+ public class Animal {
+ public int Age { get; set; }
+ public string Name { get; set; }
+ }
+ }
+}
+
diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj
index 5147be3c4..a6dc039b2 100644
--- a/src/Orchard/Orchard.Framework.csproj
+++ b/src/Orchard/Orchard.Framework.csproj
@@ -273,6 +273,8 @@
+
+
diff --git a/src/Orchard/Services/DefaultJsonConverter.cs b/src/Orchard/Services/DefaultJsonConverter.cs
new file mode 100644
index 000000000..464bc21f0
--- /dev/null
+++ b/src/Orchard/Services/DefaultJsonConverter.cs
@@ -0,0 +1,26 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Orchard.Services {
+ ///
+ /// An implementation of using the Newtonsoft.Json library
+ ///
+ public class DefaultJsonConverter : IJsonConverter {
+ public string Serialize(object o) {
+ return JsonConvert.SerializeObject(o);
+ }
+
+ public string Serialize(object o, JsonFormat format) {
+ return JsonConvert.SerializeObject(o, format == JsonFormat.Indented ? Formatting.Indented : Formatting.None);
+ }
+
+ public dynamic Deserialize(string json) {
+ dynamic result = JObject.Parse(json);
+ return result;
+ }
+
+ public T Deserialize(string json) {
+ return JsonConvert.DeserializeObject(json);
+ }
+ }
+}
diff --git a/src/Orchard/Services/IJsonConverter.cs b/src/Orchard/Services/IJsonConverter.cs
new file mode 100644
index 000000000..7dfe1ca06
--- /dev/null
+++ b/src/Orchard/Services/IJsonConverter.cs
@@ -0,0 +1,42 @@
+namespace Orchard.Services {
+ ///
+ /// Provides services to serialize and deserialize objects to and from
+ /// Json documents.
+ ///
+ public interface IJsonConverter : IDependency {
+ ///
+ /// Serializes an object to Json.
+ ///
+ /// The object to serialize.
+ /// A string representing the object as Json.
+ string Serialize(object o);
+
+ ///
+ /// Serializes an object to Json using an optional indentation.
+ ///
+ /// The object to serialize.
+ /// Whether the document should be indented.
+ /// A string representing the object as Json.
+ string Serialize(object o, JsonFormat format);
+
+ ///
+ /// Deserializes a Json document to a dynamic object.
+ ///
+ /// The Json document to deserialize.
+ /// The deserialized object.
+ dynamic Deserialize(string json);
+
+ ///
+ /// Deserializes a Json document to a specific object.
+ ///
+ /// The type of the object to deserialize.
+ /// The Json document to deserialize.
+ /// The deserialized object.
+ T Deserialize(string json);
+ }
+
+ public enum JsonFormat {
+ None,
+ Indented
+ }
+}