-Added a special case to correctly deserialize Version class

-Changed Silverlight and Windows Phone assemblies in NuGet to be strong named
-Changed CamelCasePropertyNamesContractResolver to improve camel casing property names
-Fixed QuoteChar not being used when writing DateTimes, TimeSpans, Uris and Guids
This commit is contained in:
James Newton-King
2012-11-04 14:44:55 +13:00
parent b51b3aa20a
commit c06c7b8aae
13 changed files with 151 additions and 46 deletions
@@ -113,5 +113,18 @@ namespace Newtonsoft.Json.Tests.Converters
DeserializeVersionClass("1.2.3", "2.3.4");
DeserializeVersionClass("1.2.3.4", "2.3.4.5");
}
[Test]
public void RoundtripImplicitConverter()
{
var version = new Version(1, 0, 0, 0);
string reportJSON = JsonConvert.SerializeObject(version);
//Test
Version report2 = JsonConvert.DeserializeObject<Version>(reportJSON);
string reportJSON2 = JsonConvert.SerializeObject(report2);
Assert.AreEqual(reportJSON, reportJSON2);
}
}
}
@@ -854,5 +854,43 @@ _____'propertyName': NaN
Assert.AreEqual("{'Blah':null}", sw.ToString());
}
#if !NET20
[Test]
public void QuoteChar()
{
StringWriter sw = new StringWriter();
JsonTextWriter writer = new JsonTextWriter(sw);
writer.Formatting = Formatting.Indented;
writer.QuoteChar = '\'';
writer.WriteStartArray();
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc));
writer.WriteValue(new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero));
writer.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
writer.WriteValue(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc));
writer.WriteValue(new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero));
writer.WriteValue(new byte[] { 1, 2, 3 });
writer.WriteValue(TimeSpan.Zero);
writer.WriteValue(new Uri("http://www.google.com/"));
writer.WriteValue(Guid.Empty);
writer.WriteEnd();
Assert.AreEqual(@"[
'2000-01-01T01:01:01Z',
'2000-01-01T01:01:01+00:00',
'\/Date(946688461000)\/',
'\/Date(946688461000+0000)\/',
'AQID',
'00:00:00',
'http://www.google.com/',
'00000000-0000-0000-0000-000000000000'
]", sw.ToString());
}
#endif
}
}
@@ -274,6 +274,7 @@
<Compile Include="TestObjects\UserNullable.cs" />
<Compile Include="Utilities\DynamicReflectionDelegateFactoryTests.cs" />
<Compile Include="Utilities\ReflectionUtilsTests.cs" />
<Compile Include="Utilities\StringUtilsTests.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
@@ -293,6 +293,7 @@
<Compile Include="TestObjects\UserNullable.cs" />
<Compile Include="Utilities\DynamicReflectionDelegateFactoryTests.cs" />
<Compile Include="Utilities\ReflectionUtilsTests.cs" />
<Compile Include="Utilities\StringUtilsTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.csproj">
@@ -76,5 +76,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.5.10.15503")]
[assembly: AssemblyFileVersion("4.5.10.15504")]
#endif
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests.Utilities
{
[TestFixture]
public class StringUtilsTests : TestFixtureBase
{
[Test]
public void ToCamelCaseTest()
{
Assert.AreEqual("urlValue", StringUtils.ToCamelCase("URLValue"));
Assert.AreEqual("url", StringUtils.ToCamelCase("URL"));
Assert.AreEqual("id", StringUtils.ToCamelCase("ID"));
Assert.AreEqual("i", StringUtils.ToCamelCase("I"));
Assert.AreEqual("", StringUtils.ToCamelCase(""));
Assert.AreEqual(null, StringUtils.ToCamelCase(null));
Assert.AreEqual("iPhone", StringUtils.ToCamelCase("iPhone"));
Assert.AreEqual("person", StringUtils.ToCamelCase("Person"));
Assert.AreEqual("iPhone", StringUtils.ToCamelCase("IPhone"));
Assert.AreEqual("i Phone", StringUtils.ToCamelCase("I Phone"));
Assert.AreEqual(" IPhone", StringUtils.ToCamelCase(" IPhone"));
}
}
}