diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs index 89ec0e83..bc30b234 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs @@ -1339,6 +1339,32 @@ _____'propertyName': NaN ""1ytreporP"": NULL!!! }}}", sw.ToString()); } + + [Test] + public void QuoteDictionaryNames() + { + var d = new Dictionary + { + { "a", 1 }, + }; + var jsonSerializerSettings = new JsonSerializerSettings + { + Formatting = Formatting.Indented, + }; + var serializer = JsonSerializer.Create(jsonSerializerSettings); + using (var stringWriter = new StringWriter()) + { + using (var writer = new JsonTextWriter(stringWriter) { QuoteName = false }) + { + serializer.Serialize(writer, d); + writer.Close(); + } + + Assert.AreEqual(@"{ + a: 1 +}", stringWriter.ToString()); + } + } } public class CustomJsonTextWriter : JsonTextWriter diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index 79905512..5e080594 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -35,7 +35,8 @@ ..\packages\NUnit.2.6.2\lib\nunit.framework.dll - + + False ..\packages\Microsoft.Bcl.Immutable.1.0.12-beta\lib\portable-net45+win8+wp8\System.Collections.Immutable.dll diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index c071019a..313ccace 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -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.16317")] +[assembly: AssemblyFileVersion("5.0.6.16320")] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs index 9f4c8273..ab007af4 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs @@ -25,7 +25,10 @@ using System; using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Tests.TestObjects; #if NET20 using Newtonsoft.Json.Utilities.LinqBridge; @@ -690,6 +693,40 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(@"{""Scott"":[],""James"":[]}", output); } + + [Test] + public void NoObjectWithEvent() + { + string json = "{\"}"; + byte[] byteArray = Encoding.UTF8.GetBytes(json); + MemoryStream stream = new MemoryStream(byteArray); + JsonTextReader jReader = new JsonTextReader(new StreamReader(stream)); + JsonSerializer s = new JsonSerializer(); + s.Error += (sender, args) => + { + args.ErrorContext.Handled = true; + }; + ErrorPerson2 obj = s.Deserialize(jReader); + + Assert.IsNull(obj); + } + + [Test] + public void NoObjectWithAttribute() + { + string json = "{\"}"; + byte[] byteArray = Encoding.UTF8.GetBytes(json); + MemoryStream stream = new MemoryStream(byteArray); + JsonTextReader jReader = new JsonTextReader(new StreamReader(stream)); + JsonSerializer s = new JsonSerializer(); + + ExceptionAssert.Throws( + @"Unterminated string. Expected delimiter: "". Path '', line 1, position 3.", + () => + { + ErrorTestObject obj = s.Deserialize(jReader); + }); + } } interface IErrorPerson2 @@ -777,4 +814,12 @@ namespace Newtonsoft.Json.Tests.Serialization public string Code { get; set; } public int Priority { get; set; } } + + public class ErrorTestObject + { + [OnError] + internal void OnError(StreamingContext context, ErrorContext errorContext) + { + } + } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/packages.config b/Src/Newtonsoft.Json.Tests/packages.config new file mode 100644 index 00000000..9776ceca --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonTextWriter.cs b/Src/Newtonsoft.Json/JsonTextWriter.cs index b181e0f0..93c2f07c 100644 --- a/Src/Newtonsoft.Json/JsonTextWriter.cs +++ b/Src/Newtonsoft.Json/JsonTextWriter.cs @@ -370,7 +370,7 @@ namespace Newtonsoft.Json private void WriteEscapedString(string value) { EnsureWriteBuffer(); - JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, true, _charEscapeFlags, StringEscapeHandling, ref _writeBuffer); + JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, _quoteName, _charEscapeFlags, StringEscapeHandling, ref _writeBuffer); } /// diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index c7d8d269..ba65defb 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -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.16317")] +[assembly: AssemblyFileVersion("5.0.6.16320")] [assembly: CLSCompliant(true)] diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs index 25668a51..c81b9903 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs @@ -128,7 +128,8 @@ namespace Newtonsoft.Json.Serialization TraceWriter.Trace(TraceLevel.Error, message, ex); } - if (contract != null) + // attribute method is non-static so don't invoke if no object + if (contract != null && currentObject != null) contract.InvokeOnError(currentObject, Serializer.Context, errorContext); if (!errorContext.Handled)