Exemple #1
0
        public static string Serialize <T>(this JsonSchema s, T o, JsonSchemaValidationContext c = null)
        {
            var f = new JsonFormatter();

            s.Serialize(f, o, c);
            return(f.ToString());
        }
Exemple #2
0
        public static string Serialize <T>(this JsonSchema s, T o)
        {
            var f = new JsonFormatter();

            s.Serialize(f, o);
            return(f.ToString());
        }
Exemple #3
0
        public void IndentTest()
        {
            var formatter = new JsonFormatter(2);

            formatter.BeginMap();
            formatter.Key("a"); formatter.Value(1);
            formatter.EndMap();

            var json = formatter.ToString();

            Debug.Log(json);
        }
Exemple #4
0
        public string Serialize(Object o)
        {
            var c = new JsonSchemaValidationContext(o);

            var ex = Validator.Validate(c, o);

            if (ex != null)
            {
                throw ex;
            }

            var f = new JsonFormatter();

            Validator.Serialize(f, c, o);
            return(f.ToString());
        }
        public void CreateFromClass()
        {
            var s = JsonSchema.FromType <Person>();

            Assert.AreEqual("Person", s.Title);

            var v = s.Validator as JsonObjectValidator;

            Assert.AreEqual("Age in years", v.Properties["age"].Description);
            //Assert.AreEqual(0, s.Properties["age"].Minimum);
            Assert.AreEqual(new[] { "firstName", "lastName" }, v.Required);

            var f = new JsonFormatter(2);

            s.ToJson(f);
            Debug.Log(f.ToString());
        }
Exemple #6
0
        public void CreateFromClass()
        {
            var s = JsonSchema.FromType <Person>();

            Assert.AreEqual("Person", s.Title);

            var v = s.Validator as JsonObjectValidator;

            Assert.AreEqual("Age in years", v.Properties["age"].Description);
            Assert.AreEqual(new[] { "firstName", "lastName" }, v.Required);

            var f = new JsonFormatter(2);

            s.ToJson(f);
            var json = f.ToString();

            var parsed = JsonParser.Parse(json);

            Assert.AreEqual(0, parsed["properties"]["age"]["minimum"].GetInt32());
        }