Example #1
1
        public void ComplexTest()
        {
            var instance = new TestClass
              {
            Bar = new TestClass1
            {
              Foo = "test"
            }
              };

              var str = TypeSerializer.SerializeToString(instance);

              var jsv = new JsvConverter();

              var result = jsv.DeserializeFromString<TestClass>(str);

              Assert.AreEqual("test", result.Bar.Foo);

              var foo = new TestClass1
              {
            Foo = "test1"
              };

              var result1 = jsv.DeserializeFromString<TestClass1>(TypeSerializer.SerializeToString(foo));

              Assert.AreEqual("test1", result1.Foo);
        }
Example #2
0
        public void UnknownPropertiesAreSkipped_3()
        {
            var str = "{Bar:\"x,\", Foo:\"test\"}";

              var jsv = new JsvConverter();

              var result = jsv.DeserializeFromString<TestClass>(str);

              Assert.AreEqual("test", result.Foo);
        }
Example #3
0
        public void DeserializeSimpleStringWorksWithLiteralNewLines()
        {
            var jsv = new JsvConverter();
              var str = "{Foo:Test,Test:1,Foobar:ssdfsdfsdfsdf\n\n\n\n}";
              var result = jsv.DeserializeFromString<TestClass1>(str);

              Assert.AreEqual("Test", result.Foo);
              Assert.AreEqual(1, result.Test);
              Assert.AreEqual("ssdfsdfsdfsdf", result.Foobar);
        }
Example #4
0
        public void IntCollectionIsDeserialized_4()
        {
            var str = "{Ints:[1, 2aa, 3,  ],Foo:test3}";

              var jsv = new JsvConverter();

              var result = jsv.DeserializeFromString<TestClass>(str);

              Assert.IsTrue(result.Ints.SequenceEqual(new[] { 1, 2, 3 }));
              Assert.AreEqual("test3", result.Foo);
        }
Example #5
0
        public void VerifyTemplate()
        {
            var customer = Create();

              var serialized = TypeSerializer.SerializeToString(customer);

              var jsv = new JsvConverter();

              var deserialized = jsv.DeserializeFromString<Customer>(serialized);

              DoAsserts(customer, deserialized);
        }
Example #6
0
        public void Test_1()
        {
            var instance = new DateTimeProperty
              {
            Date = new DateTime(2013, 10, 1, 14, 45, 28, DateTimeKind.Local)
              };

              var serialized = TypeSerializer.SerializeToString(instance);

              var deserializer = new JsvConverter();

              var result = deserializer.DeserializeFromString<DateTimeProperty>(serialized);
        }
Example #7
0
        public static void Benchmark()
        {
            var instance = Create();

              var str = TypeSerializer.SerializeToString(instance);

              var result = TypeSerializer.DeserializeFromString<Customer>(str);

              var jsv = new JsvConverter();
              result = null;
              result = jsv.DeserializeFromString<Customer>(str);

              Console.WriteLine(result);

              var sw = Stopwatch.StartNew();

              // Servicestack.Text
              for (var i = 0; i < 1000000; i++)
              {
            result = TypeSerializer.DeserializeFromString<Customer>(str);
              }

              sw.Stop();

              Console.WriteLine(sw.Elapsed);

              sw.Restart();

              // Marlee.Jsv
              for (var i = 0; i < 1000000; i++)
              {
            result = jsv.DeserializeFromString<Customer>(str);
              }

              sw.Stop();

              Console.WriteLine(sw.Elapsed);
        }
Example #8
0
        public void DeserializeSimpleStringWorksWithArbitraryWhiteSpace()
        {
            var jsv = new JsvConverter();
              var str = @"
            {
              Foo:    Test,
              Test  : 1,
              Foobar      :ssdfsdfsdfsdf,,,,
            }";
              var result = jsv.DeserializeFromString<TestClass1>(str);

              Assert.AreEqual("Test", result.Foo);
              Assert.AreEqual(1, result.Test);
              Assert.AreEqual("ssdfsdfsdfsdf", result.Foobar);
        }
Example #9
0
        public void IntCollectionIsDeserialized_5()
        {
            var str = "{Ints:[1, 2, 3, aaa ],Foo:test3}";

              var jsv = new JsvConverter();

              var result = jsv.DeserializeFromString<TestClass>(str);
        }
Example #10
0
        public void DeserializeSimpleStringWorksWithMultiLineAndTrailingComma()
        {
            var jsv = new JsvConverter();
              var str = @"
            {
              Foo:Test,
              Test:1,
              Foobar:ssdfsdfsdfsdf,
            }";
              var result = jsv.DeserializeFromString<TestClass1>(str);

              Assert.AreEqual("Test", result.Foo);
              Assert.AreEqual(1, result.Test);
              Assert.AreEqual("ssdfsdfsdfsdf", result.Foobar);
        }
Example #11
0
        public void SinglePropertyWorks()
        {
            var str = "{Foo:test}";

              var jsv = new JsvConverter();
              var result = jsv.DeserializeFromString<TestClass3>(str);

              Assert.AreEqual("test", result.Foo);
        }
Example #12
0
        public void PropertyOrderIsNotImportant()
        {
            var jsv = new JsvConverter();
              var str = "{Test:1,Foo:Test,Foobar:ssdfsdfsdfsdf}";
              var result = jsv.DeserializeFromString<TestClass1>(str);

              Assert.AreEqual("Test", result.Foo);
              Assert.AreEqual(1, result.Test);
              Assert.AreEqual("ssdfsdfsdfsdf", result.Foobar);
        }
Example #13
0
        public void DeserializeSimpleStringWorksWithQuotedValues_1()
        {
            var obj = new TestClass1
              {
            Foo = "Test",
            Test = 1,
            Foobar = @"ssdfs""df""sdfsdf"
              };

              var str = TypeSerializer.SerializeToString(obj);

              var jsv = new JsvConverter();
              //var str = @"{Foo:Test,Test:1,Foobar:""ssdfs""""df""""sdfsdf""}";
              var result = jsv.DeserializeFromString<TestClass1>(str);

              Assert.AreEqual("Test", result.Foo);
              Assert.AreEqual(1, result.Test);
              Assert.AreEqual(@"ssdfs""df""sdfsdf", result.Foobar);
        }
Example #14
0
        public void DeserializeSimpleStringWorksWithQuotedValues()
        {
            var jsv = new JsvConverter();
              var str = @"{Foo:Test,Test:1,Foobar:""ssdfsdfsdfsdf""}";
              var result = jsv.DeserializeFromString<TestClass1>(str);

              Assert.AreEqual("Test", result.Foo);
              Assert.AreEqual(1, result.Test);
              Assert.AreEqual("ssdfsdfsdfsdf", result.Foobar);
        }