diff --git a/Manatee.Json.Tests/ClientTest.cs b/Manatee.Json.Tests/ClientTest.cs
index 39095ff..38f0fc0 100644
--- a/Manatee.Json.Tests/ClientTest.cs
+++ b/Manatee.Json.Tests/ClientTest.cs
@@ -319,31 +319,44 @@ public void Issue49_RequiredAndAllOfInSingleSchema()
public void Issue50_MulitpleSchemaInSubFoldersShouldReferenceRelatively()
{
string path = System.IO.Path.Combine(TestContext.TestDeploymentDir, @"Files\Issue50A.json");
-
var schema = JsonSchemaRegistry.Get(path);
var json = new JsonObject
- {
- ["text"] = "something",
- ["refa"] = new JsonObject
{
- ["text"] = "something else",
- ["refb"] = new JsonObject()
- {
- ["refd"] = new JsonObject()
+ ["text"] = "something",
+ ["refa"] = new JsonObject
{
- ["refe"] = new JsonObject() {
- ["test"] = "test"
- },
- ["text"] = "test"
+ ["text"] = "something else",
+ ["refb"] = new JsonObject
+ {
+ ["refd"] = new JsonObject
+ {
+ ["refe"] = new JsonObject{["test"] = "test"},
+ ["text"] = "test"
+ }
+ }
}
- }
- }
- };
-
-
+ };
var results = schema.Validate(json);
-
Assert.IsTrue(results.Valid);
}
+
+ [TestMethod]
+ public void Issue56_InconsistentNullAssignment()
+ {
+ JsonValue json1 = null; // this is actually null
+ string myVar = null;
+ JsonValue json2 = myVar; // this is JsonValue.Null
+
+ Assert.IsNull(json1);
+ Assert.IsTrue(Equals(null, json1));
+
+ Assert.IsNotNull(json2);
+ Assert.IsTrue(null == json2);
+ // R# isn't considering my == overload
+ // ReSharper disable once HeuristicUnreachableCode
+ Assert.IsTrue(json2.Equals(null));
+ // This may seem inconsistent, but check out the notes in the issue.
+ Assert.IsFalse(Equals(null, json2));
+ }
}
}
diff --git a/Manatee.Json.Tests/Files/issue55.json b/Manatee.Json.Tests/Files/issue55.json
new file mode 100644
index 0000000..9aadb4e
--- /dev/null
+++ b/Manatee.Json.Tests/Files/issue55.json
@@ -0,0 +1,12 @@
+{
+ "$schema" : "http://json-schema.org/draft-04/schema",
+ "title" : "JSON Schema for Universally Unique Identifiers (UUIDs).",
+ "type" : "object",
+ "properties": {
+ "uuid":{
+ "description": "A universally unique identifier (UUID).",
+ "type":"string",
+ "pattern": "^([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})|[a-f0-9]{32}$"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Manatee.Json.Tests/Manatee.Json.Tests.csproj b/Manatee.Json.Tests/Manatee.Json.Tests.csproj
index 6c0219b..a4c2eed 100644
--- a/Manatee.Json.Tests/Manatee.Json.Tests.csproj
+++ b/Manatee.Json.Tests/Manatee.Json.Tests.csproj
@@ -112,6 +112,9 @@
Always
+
+ Always
+
Always
diff --git a/Manatee.Json/JsonValue.cs b/Manatee.Json/JsonValue.cs
index afa960e..af48c43 100644
--- a/Manatee.Json/JsonValue.cs
+++ b/Manatee.Json/JsonValue.cs
@@ -14,7 +14,7 @@ namespace Manatee.Json
/// A value can consist of a string, a numerical value, a boolean (true or false), a null
/// placeholder, a JSON array of values, or a nested JSON object.
///
- public class JsonValue
+ public class JsonValue : IEquatable
{
private bool _boolValue;
private string _stringValue;
@@ -256,21 +256,32 @@ public override string ToString()
/// The to compare with the current . 2
public override bool Equals(object obj)
{
- var json = obj.AsJsonValue();
- if (json == null) return false;
- if (json.Type != Type) return false;
+ if (obj == null) return Type == JsonValueType.Null;
+
+ return Equals(obj.AsJsonValue());
+ }
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ /// An object to compare with this object.
+ public bool Equals(JsonValue other)
+ {
+ // using a == here would result in recursion and death by stack overflow
+ if (ReferenceEquals(other, null)) return Type == JsonValueType.Null;
+ if (other.Type != Type) return false;
switch (Type)
{
case JsonValueType.Number:
- return Number.Equals(json.Number);
+ return Number.Equals(other.Number);
case JsonValueType.String:
- return String.Equals(json.String);
+ return String.Equals(other.String);
case JsonValueType.Boolean:
- return Boolean.Equals(json.Boolean);
+ return Boolean.Equals(other.Boolean);
case JsonValueType.Object:
- return Object.Equals(json.Object);
+ return Object.Equals(other.Object);
case JsonValueType.Array:
- return Array.Equals(json.Array);
+ return Array.Equals(other.Array);
case JsonValueType.Null:
return true;
}
@@ -453,7 +464,7 @@ public static JsonValue Parse(StreamReader stream)
///
public static bool operator ==(JsonValue a, JsonValue b)
{
- return ReferenceEquals(a,b) || ((a != null) && (a.Equals(b)));
+ return ReferenceEquals(a, b) || (a != null ? a.Equals(b) : b.Equals(a));
}
///
///
diff --git a/Manatee.Json/Properties/AssemblyInfo.cs b/Manatee.Json/Properties/AssemblyInfo.cs
index 555ee76..04e5af4 100644
--- a/Manatee.Json/Properties/AssemblyInfo.cs
+++ b/Manatee.Json/Properties/AssemblyInfo.cs
@@ -33,6 +33,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.0.0")]
-[assembly: AssemblyFileVersion("6.0.0")]
+[assembly: AssemblyFileVersion("6.0.1")]
[assembly: InternalsVisibleTo("Manatee.Json.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bbe54aad91e473ca58d56672e66770435869a2388ac5a077457bf23b0872f5d656414709391f78751fd762ec25132d42ad60e319b821e37357964ac194b31a52e1d9772c507aed15527ff41564fdf85c7a90b09b7f8c8c321daf05404e7ccdaee0b5808db8aaa0ac2e8e3065509b5f1c75c4d1de5ceed995ae83fd36d10e8be0")]
diff --git a/Manatee.Json/Schema/Validators/TypeSchemaPropertyValidator.cs b/Manatee.Json/Schema/Validators/TypeSchemaPropertyValidator.cs
index 3b3c63d..b933666 100644
--- a/Manatee.Json/Schema/Validators/TypeSchemaPropertyValidator.cs
+++ b/Manatee.Json/Schema/Validators/TypeSchemaPropertyValidator.cs
@@ -35,19 +35,19 @@ public SchemaValidationResults Validate(JsonSchema schema, JsonValue json, JsonV
case JsonValueType.String:
if (JsonSchemaTypeDefinition.PrimitiveDefinitions.Any(d => d.Name == json.String)) break;
if (Equals(schema.Type, JsonSchemaTypeDefinition.String)) break;
- return new SchemaValidationResults(string.Empty, $"Expected: String; Actual: {json.Type}.");
+ return new SchemaValidationResults(string.Empty, $"Expected: {schema.Type.Name}; Actual: {json.Type}.");
case JsonValueType.Boolean:
if (Equals(schema.Type, JsonSchemaTypeDefinition.Boolean)) break;
- return new SchemaValidationResults(string.Empty, $"Expected: Boolean; Actual: {json.Type}.");
+ return new SchemaValidationResults(string.Empty, $"Expected: {schema.Type.Name}; Actual: {json.Type}.");
case JsonValueType.Object:
if (Equals(schema.Type, JsonSchemaTypeDefinition.Object)) break;
- return new SchemaValidationResults(string.Empty, $"Expected: Object; Actual: {json.Type}.");
+ return new SchemaValidationResults(string.Empty, $"Expected: {schema.Type.Name}; Actual: {json.Type}.");
case JsonValueType.Array:
if (Equals(schema.Type, JsonSchemaTypeDefinition.Array)) break;
- return new SchemaValidationResults(string.Empty, $"Expected: Array; Actual: {json.Type}.");
+ return new SchemaValidationResults(string.Empty, $"Expected: {schema.Type.Name}; Actual: {json.Type}.");
case JsonValueType.Null:
if (Equals(schema.Type, JsonSchemaTypeDefinition.Null)) break;
- return new SchemaValidationResults(string.Empty, $"Expected: Null; Actual: {json.Type}.");
+ return new SchemaValidationResults(string.Empty, $"Expected: {schema.Type.Name}; Actual: {json.Type}.");
}
return new SchemaValidationResults();
}
diff --git a/Manatee.Json/project.nuspec b/Manatee.Json/project.nuspec
index ceea14e..66058a0 100644
--- a/Manatee.Json/project.nuspec
+++ b/Manatee.Json/project.nuspec
@@ -2,7 +2,7 @@
Manatee.Json
- 6.0.0
+ 6.0.1
A fully object-oriented approach to JSON manipulation, validation, and serialization that focuses on modeling the JSON structure rather than mere string parsing.
@@ -12,6 +12,10 @@
https://github.com/gregsdennis/Manatee.Json/blob/master/LICENSE.txt
https://bytebucket.org/gregsdennis/manatee.json/wiki/Resources/Manatee-Json-Logo.png
+ v6.0.1
+ Updated equality logic to further unify .Net-null and JSON-null. Please read Equality Comparisons section of Usage wiki page.
+ BUG FIX: Vague error messaging when validating schema. (#55)
+
v6.0.0
Added DocumentPath to IJsonSchema.
BUG FIX: Schema now properly resolve referenced schema relative to document path instead of application's current directory. (#50)
diff --git a/Wiki b/Wiki
index 3537c0e..b06e173 160000
--- a/Wiki
+++ b/Wiki
@@ -1 +1 @@
-Subproject commit 3537c0e7c780be8cbab689bd0972d3a7db272d54
+Subproject commit b06e173b927c852984a1a16b94b6e263cd3cf2f1