예제 #1
0
        public static void JsonIgnoreTest()
        {
            JsonTestClass cls = new TestCases.JsonTest.JsonTestClass();
            var           str = JsonMapper.ToJson(cls);

            Console.WriteLine(str);

            if (str.Contains("IntProp") == false)
            {
                throw new Exception("IntProp should be serilized");
            }

            if (str.Contains("IgnoreField"))
            {
                throw new Exception("Ignore Field should not be serilized");
            }

            if (str.Contains("IgnoreProp"))
            {
                throw new Exception("Ignore Prop should not be serilized");
            }

            Console.WriteLine(str);
            var cls2 = JsonMapper.ToObject <JsonTestClass>(str);
        }
예제 #2
0
        public static void JsonTest1()
        {
            JsonTestClass cls = new TestCases.JsonTest.JsonTestClass();

            cls.IntProp    = 1;
            cls.StringProp = "2";
            cls.EnumProp   = JsonTestEnum.Test3;
            var sub = new TestCases.JsonTest.JsonTestSubClass();

            sub.LongProp = 4;
            var sub2 = new TestCases.JsonTest.JsonTestSubClass();

            sub2.LongProp = 5;
            var sub3 = new TestCases.JsonTest.JsonTestSubClass();

            sub3.LongProp = 6;

            cls.SubClassProp = sub;
            sub.ArrayProp    = new JsonTestSubClass[2];
            sub.ArrayProp[0] = sub2;
            sub.ArrayProp[1] = sub3;
            sub.SubClassList = new List <TestCases.JsonTest.JsonTestSubClass>();
            sub.SubClassList.Add(sub2);
            sub.SubClassList.Add(sub3);
            sub.SubClassEnumList = new List <JsonTestEnum>();
            sub.SubClassEnumList.Add(JsonTestEnum.Test2);

            cls.DicTest            = new Dictionary <string, TestCases.JsonTest.JsonTestSubClass>();
            cls.DicTest["11111"]   = sub;
            cls.DicTest2           = new Dictionary <string, int>();
            cls.DicTest2["111222"] = 333444;

            var str = JsonMapper.ToJson(cls);

            Console.WriteLine(str);

            var cls2 = JsonMapper.ToObject <JsonTestClass>(str);

            Console.WriteLine(cls2.SubClassProp.ArrayProp[0].LongProp);
            Console.WriteLine(cls2.SubClassProp.ArrayProp[1].LongProp);
            Console.WriteLine(cls2.SubClassProp.SubClassList[0].LongProp);
            Console.WriteLine(cls2.SubClassProp.SubClassList[1].LongProp);
            Console.WriteLine(cls2.SubClassProp.SubClassEnumList[0]);
            Console.WriteLine(cls2.DicTest["11111"].LongProp);
            Console.WriteLine(cls2.DicTest2["111222"]);
        }
예제 #3
0
        public static void JsonTest6()
        {
            JsonTestClass.StaticField = 10;
            JsonTestClass.StaticProp  = 30;

            JsonTestClass cls = new TestCases.JsonTest.JsonTestClass();
            var           str = JsonMapper.ToJson(cls);

            Console.WriteLine(str);

            if (str.Contains("StaticField"))
            {
                throw new Exception("Static Field should not be serilized");
            }

            if (str.Contains("StaticProp"))
            {
                throw new Exception("Static Field should not be serilized");
            }

            Console.WriteLine(str);
            var cls2 = JsonMapper.ToObject <JsonTestClass>(str);
        }