public void CanSerializeRowObjects()
        {
            var sample = new RowList()
                {
                    elements = new RowDTO[]
                        {
                            new AllRightAnnouncement() {announcement = "alright"}
                        }
                };

            var settings = Frontpage.MvcApplication.GetJsonSerializationSettings();

            var serializer = JsonSerializer.Create(settings);

            var sb = new StringBuilder();
            var reader = new StringWriter(sb);

            serializer.Serialize(reader, sample);

            Console.WriteLine("Serialized: " + sb.ToString());

            var result = serializer.Deserialize<RowList>(new JsonTextReader(new StringReader(sb.ToString())));

            Assert.That(result.elements.Length, Is.EqualTo(1));

            var element = result.elements.Cast<AllRightAnnouncement>().Single();

            Assert.That(element.announcement, Is.EqualTo("alright"));
        }
Ejemplo n.º 2
0
        public ActionResult Index(RowList value)
        {
            string request;

            Request.InputStream.Seek(0, SeekOrigin.Begin);
            using (var reader = new StreamReader(Request.InputStream))
            {
                request = reader.ReadToEnd();
            }

            var serializer = JsonSerializer.Create(MvcApplication.GetJsonSerializationSettings());

            serializer.TypeNameHandling = TypeNameHandling.All;

            var xnodeRequest = serializer.Deserialize <RowList>(new JsonTextReader(new StringReader(request)));

            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult Index(RowList value)
        {
            string request;

            Request.InputStream.Seek(0, SeekOrigin.Begin);
            using (var reader = new StreamReader(Request.InputStream))
            {
                request = reader.ReadToEnd();
            }

            var serializer = JsonSerializer.Create(MvcApplication.GetJsonSerializationSettings());

            serializer.TypeNameHandling = TypeNameHandling.All;

            var xnodeRequest = serializer.Deserialize<RowList>(new JsonTextReader(new StringReader(request)));

            return View();
        }