private static bool HasType(JsonValue value, string type) { switch (type) { case "object": return value is JsonObject; case "array": return value is JsonArray; case "string": return value is JsonText; case "boolean": return value is JsonTrue || value is JsonFalse; case "null": return value is JsonNull; case "integer": return value is JsonNumber && value.As<JsonNumber>().IsInteger(); case "number": return value is JsonNumber; default: return false; } }
public void Can_Deserialize_JsonValue() { var json = simple.ToJson(); var jsonValue = new JsonValue(json); var fromJson = jsonValue.As <SimpleObj>(); Assert.That(fromJson.value1, Is.EqualTo(simple.value1)); Assert.That(fromJson.value2, Is.EqualTo(simple.value2)); }
public void Can_Deserialize_JsonValue() { var json = simple.ToJson(); var jsonValue = new JsonValue(json); var fromJson = jsonValue.As<SimpleObj>(); Assert.That(fromJson.value1, Is.EqualTo(simple.value1)); Assert.That(fromJson.value2, Is.EqualTo(simple.value2)); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; JsonObject target = value.As<JsonObject>(); if (target == null) return true; foreach (string property in byName.Keys) if (target.Contains(property)) foreach (string dependency in byName[property]) if (target.Contains(dependency) == false) { JsonPathSegment segment = new JsonPropertySegment(property); callback.Fail(segment, value, $"The dependency is not valid. Missing property: {dependency}."); succeeded = false; } foreach (string property in byRule.Keys) { if (target.Contains(property)) { JsonSchemaRule rule = byRule[property]; JsonPathSegment segment = new JsonPropertySegment(property); JsonSchemaCallback scope = callback.Scope(segment); if (rule.IsValid(definitions, value, scope) == false) { callback.Add(scope); succeeded = false; } } } return succeeded; }