Ejemplo n.º 1
0
        public void DeserializeSchema_TypePropertyIsArray_Issue14()
        {
            JsonSchemaFactory.SetDefaultSchemaVersion <JsonSchema04>();

            var text     = "{\"type\":\"object\",\"properties\":{\"home\":{\"type\":[\"object\",\"null\"],\"properties\":{\"street\":{\"type\":\"string\"}}}}}";
            var json     = JsonValue.Parse(text);
            var expected = new JsonSchema04
            {
                Type       = JsonSchemaType.Object,
                Properties = new Dictionary <string, IJsonSchema>
                {
                    ["home"] = new JsonSchema04
                    {
                        Type       = JsonSchemaType.Object | JsonSchemaType.Null,
                        Properties = new Dictionary <string, IJsonSchema>
                        {
                            ["street"] = new JsonSchema04 {
                                Type = JsonSchemaType.String
                            }
                        }
                    }
                }
            };

            var actual = JsonSchemaFactory.FromJson(json);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void Online(IJsonSchema schema)
        {
            try
            {
                // TODO: Catch web exceptions and assert inconclusive.
                var localSchemaJson = schema.ToJson(null);

                var onlineSchemaText = JsonSchemaOptions.Download(schema.Id);
                var onlineSchemaJson = JsonValue.Parse(onlineSchemaText);
                var onlineSchema     = JsonSchemaFactory.FromJson(onlineSchemaJson);

                var localValidation  = schema.Validate(onlineSchemaJson);
                var onlineValidation = onlineSchema.Validate(localSchemaJson);

                Assert.AreEqual(onlineSchema, schema);

                onlineValidation.AssertValid();
                localValidation.AssertValid();

                Assert.AreEqual(onlineSchemaJson, localSchemaJson);
            }
            catch (WebException)
            {
                Assert.Inconclusive();
            }
            catch (AggregateException e)
            {
                if (e.InnerExceptions.OfType <WebException>().Any())
                {
                    Assert.Inconclusive();
                }
                throw;
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var json = new JsonObject
            {
                ["test1"] = 1,
                ["test2"] = "hello"
            };
            var serializer = new JsonSerializer();
            var obj        = serializer.Deserialize <ITest>(json);

            System.Console.WriteLine(obj.Test1);
            System.Console.WriteLine(obj.Test2);

            var schema04json = JsonSchema04.MetaSchema.ToJson(null);
            var schema04     = JsonSchemaFactory.FromJson(schema04json);

            System.Console.ReadLine();
        }
Ejemplo n.º 4
0
        public void DeclaredTypeWithDeclaredEnum_Issue15()
        {
            JsonSchemaFactory.SetDefaultSchemaVersion <JsonSchema04>();

            var text     = "{\"type\":\"string\",\"enum\":[\"FeatureCollection\"]}";
            var json     = JsonValue.Parse(text);
            var expected = new JsonSchema04
            {
                Type = JsonSchemaType.String,
                Enum = new List <EnumSchemaValue>
                {
                    new EnumSchemaValue("FeatureCollection")
                }
            };

            var actual = JsonSchemaFactory.FromJson(json);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public T Deserialize <T>(JsonValue json, JsonSerializer serializer)
        {
            var value = JsonSchemaFactory.FromJson(json);

            return((T)value);
        }