diff options
author | JamesNK <james@newtonking.com> | 2012-02-11 11:00:18 +0400 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2012-02-11 11:00:18 +0400 |
commit | 7b908df64d2fe74597d3ee5f634ebcc33ffff144 (patch) | |
tree | 21bc47c5c405344eb6bd7159873c8193397e0045 | |
parent | 2dd26baa770528f30331e0a07e7f639b3e78c1a8 (diff) |
-Fixed JsonValidatingReader.ReadAsBytes throwing exception
-Minor NuGet spec updates
-rw-r--r-- | Build/Newtonsoft.Json.nuspec | 7 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs | 72 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/JsonValidatingReader.cs | 4 |
3 files changed, 78 insertions, 5 deletions
diff --git a/Build/Newtonsoft.Json.nuspec b/Build/Newtonsoft.Json.nuspec index 3495d31..53e2f34 100644 --- a/Build/Newtonsoft.Json.nuspec +++ b/Build/Newtonsoft.Json.nuspec @@ -1,13 +1,14 @@ <?xml version="1.0" encoding="utf-8"?>
-<package>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Newtonsoft.Json</id>
- <title>Json.NET</title>
<version>4.0.8</version>
- <authors>James Newton-King</authors>
+ <title>Json.NET</title>
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
+ <authors>James Newton-King</authors>
<language>en-US</language>
<projectUrl>http://james.newtonking.com/projects/json-net.aspx</projectUrl>
+ <licenseUrl>http://json.codeplex.com/license</licenseUrl>
<tags>json</tags>
</metadata>
</package>
\ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs b/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs index a0ec484..6845069 100644 --- a/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs @@ -1360,5 +1360,77 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual(1, validationEventArgs.Count);
}
+
+ [Test]
+ public void ReadAsBytes()
+ {
+ JsonSchema s = new JsonSchemaGenerator().Generate(typeof (byte[]));
+
+ byte[] data = Encoding.UTF8.GetBytes("Hello world");
+
+ JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"""" + Convert.ToBase64String(data) + @"""")))
+ {
+ Schema = s
+ };
+ byte[] bytes = reader.ReadAsBytes();
+
+ Assert.AreEqual(data, bytes);
+ }
+
+ [Test]
+ public void ReadAsInt32()
+ {
+ JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
+
+ JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1")))
+ {
+ Schema = s
+ };
+ int? i = reader.ReadAsInt32();
+
+ Assert.AreEqual(1, i);
+ }
+
+ [Test]
+ [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 5 exceeds maximum value of 2. Line 1, position 1.")]
+ public void ReadAsInt32Failure()
+ {
+ JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
+ s.Maximum = 2;
+
+ JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
+ {
+ Schema = s
+ };
+ reader.ReadAsInt32();
+ }
+
+ [Test]
+ public void ReadAsDecimal()
+ {
+ JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
+
+ JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1.5")))
+ {
+ Schema = s
+ };
+ decimal? d = reader.ReadAsDecimal();
+
+ Assert.AreEqual(1.5, d);
+ }
+
+ [Test]
+ [ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Float 5.5 is not evenly divisible by 1. Line 1, position 3.")]
+ public void ReadAsDecimalFailure()
+ {
+ JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
+ s.DivisibleBy = 1;
+
+ JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
+ {
+ Schema = s
+ };
+ reader.ReadAsDecimal();
+ }
}
}
\ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index 4e2f691..fd5e539 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -423,8 +423,6 @@ namespace Newtonsoft.Json _model = builder.Build(_schema);
}
- //ValidateValueToken();
-
switch (_reader.TokenType)
{
case JsonToken.StartObject:
@@ -503,6 +501,8 @@ namespace Newtonsoft.Json Pop();
break;
case JsonToken.Date:
+ case JsonToken.Bytes:
+ // these have no equivalent in JSON schema
break;
default:
throw new ArgumentOutOfRangeException();
|