Beispiel #1
0
        public void ToJson()
        {
            var target = new Target()
            {
                Targets =
                {
                    new Target1(),
                    new Target2(),
                    new Target3()
                }
            };

            var serializer = JsonSerializer.CreateDefault(JsonNetUtility.DefaultSettings);

            var writer = new ConvertPropertyNameWriter(new Dictionary <string, string>
            {
                { "$type", "type" }
            });

            serializer.Serialize(writer, target);

            string result = writer.TextWriter.ToString();

            result = JsonNetUtility.Format(result);

            Assert.Pass(result);
        }
Beispiel #2
0
        public void ToJsonWithBinder()
        {
            var target = new Target()
            {
                Targets =
                {
                    new Target1(),
                    new Target2(),
                    new Target3()
                }
            };

            var binder = new ConvertTypeNameBinder();
            JsonSerializerSettings settings = JsonNetUtility.CreateDefault();

            settings.SerializationBinder = binder;

            binder.Provider.Add <Target1>("target1");
            binder.Provider.Add <Target2>("target2");

            var serializer = JsonSerializer.CreateDefault(settings);

            var writer = new ConvertPropertyNameWriter(new Dictionary <string, string>
            {
                { "$type", "type" }
            });

            serializer.Serialize(writer, target);

            string result = writer.TextWriter.ToString();

            result = JsonNetUtility.Format(result);

            Assert.Pass(result);
        }
        public void Format()
        {
            string compact0  = Resources.Load <TextAsset>("data1").text;
            string readable0 = Resources.Load <TextAsset>("data2").text;

            string readable1 = JsonNetUtility.Format(compact0);
            string compact1  = JsonNetUtility.Format(readable0, false);

            Assert.AreEqual(readable0, readable1);
            Assert.AreEqual(compact0, compact1);
        }