Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

APJSON

, 28 Aug 2013
This is an alternative for "fastJSON"
Apolyton_FastJson_Binaries__v0.92_.zip
Output
Debug
Apolyton.FastJson.dll
Apolyton.FastJson.pdb
Release x64
Apolyton.FastJson.dll
Release x86
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
consoletest.vshost.exe.manifest
fastJSON.dll
Release
Apolyton.FastJson.dll
Silverlight
Apolyton.Json.Silverlight.dll
Apolyton.Json.Silverlight.pdb
Apolyton_FastJson_Binaries__v0.93_.zip
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Apolyton.Json.Silverlight.dll
Apolyton_FastJson_Binaries__v0.9_.zip
Apolyton.FastJson.dll
Apolyton.FastJson.pdb
Apolyton.FastJson.dll
Apolyton.FastJson.pdb
consoletest.exe
consoletest.vshost.exe
consoletest.vshost.exe.manifest
fastJSON.dll
fastJSON.pdb
Apolyton.FastJson.dll
Apolyton.FastJson.pdb
consoletest.exe
consoletest.vshost.exe
consoletest.vshost.exe.manifest
fastJSON.dll
fastJSON.pdb
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Apolyton_FastJson_Binaries__v1.0_.zip
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
consoletest.vshost.exe.manifest
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Apolyton.Json.Silverlight.dll
apolyton_fastjson_sources__v0.92_.zip
Apolyton.FastJson
Apolyton.FastJson.csproj.user
Apolyton.FastJson.Silverlight.csproj.user
Apolyton.FastJson.v11.suo
Bin
Debug
Apolyton.Json.Silverlight.dll
Apolyton.Json.Silverlight.pdb
Common
Data
Diagram.cd
obj
Debug
Apolyton.FastJson.dll
Apolyton.FastJson.pdb
Apolyton.Json.Silverlight.dll
Apolyton.Json.Silverlight.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release x64
Apolyton.FastJson.dll
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release x86
Apolyton.FastJson.dll
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release
Apolyton.FastJson.dll
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
Registry
Serialization
Apolyton.FastJson.Tests
bin
Debug
Release
Apolyton.FastJson.dll
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.pdb
Data
Helpers
ComplexTypes
ParameterRelated
Polymorphism
RegistryHelpers
StandardTypes
obj
Debug
Apolyton.FastJson.Tests.csprojResolveAssemblyReference.cache
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.pdb
build.force
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release (x86, CUSTOM TYPES)
build.force
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release
Apolyton.FastJson.Tests.csprojResolveAssemblyReference.cache
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
Registry
Serialization
Console Test
bin
Debug
Apolyton.FastJson.dll
Apolyton.FastJson.pdb
consoletest.exe
consoletest.pdb
consoletest.vshost.exe
fastJSON.dll
fastJSON.pdb
x86
DataObjects
obj
Debug
build.force
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
consoletest.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release (x86, CUSTOM TYPES)
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release x64
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release x86
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Release
build.force
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
x86
Debug
TempPE
Apolyton_FastJson_Sources__v0.93_.zip
Apolyton.FastJson.dll
Apolyton.FastJSON.Tests.dll
Apolyton.FastJson.dll
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.dll
build.force
Apolyton.FastJSON.Tests.dll
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Release
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Release (x86, CUSTOM TYPES)
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Release x64
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
Release x64
consoletest.exe
Release x86
consoletest.exe
Release
consoletest.exe
Apolyton.FastJson.csproj.user
Apolyton.FastJson.Silverlight.csproj.user
Apolyton.FastJson.v11.suo
Apolyton.Json.Silverlight.dll
Release
Apolyton.Json.Silverlight.dll
Diagrams
Json.cd
JsonParameters.cd
TypeDescriptors.cd
Apolyton.FastJson.dll
Apolyton.Json.Silverlight.dll
Apolyton.FastJson.dll
Apolyton.FastJson.dll
Apolyton.FastJson.dll
Apolyton.Json.Silverlight.dll
Apolyton_FastJson_Sources__v0.9_.zip
Apolyton.FastJson.csproj.user
Diagram.cd
Apolyton.FastJson.Tests.csprojResolveAssemblyReference.cache
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.pdb
DesignTimeResolveAssemblyReferencesInput.cache
Apolyton.FastJson.Tests.csprojResolveAssemblyReference.cache
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.pdb
DesignTimeResolveAssemblyReferencesInput.cache
build.force
DesignTimeResolveAssemblyReferencesInput.cache
consoletest.vshost.exe
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
consoletest.pdb
DesignTimeResolveAssemblyReferencesInput.cache
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
DesignTimeResolveAssemblyReferencesInput.cache
DesignTimeResolveAssemblyReferencesInput.cache
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
DesignTimeResolveAssemblyReferencesInput.cache
consoletest.csprojResolveAssemblyReference.cache
consoletest.exe
DesignTimeResolveAssemblyReferencesInput.cache
Apolyton_FastJson_Sources__v1.0_.zip
Apolyton.FastJson.csproj.user
Apolyton.FastJson.Silverlight.csproj.user
Apolyton.FastJson.v11.suo
Apolyton.Json.Silverlight.dll
Apolyton.Json.Silverlight.dll
Json.cd
JsonParameters.cd
TypeDescriptors.cd
Apolyton.FastJson.dll
Apolyton.Json.Silverlight.dll
Apolyton.FastJson.dll
Apolyton.FastJson.dll
Apolyton.FastJson.dll
Apolyton.Json.Silverlight.dll
Apolyton.FastJson.dll
Apolyton.FastJSON.Tests.dll
Apolyton.FastJson.dll
Apolyton.FastJSON.Tests.dll
Apolyton.FastJSON.Tests.dll
build.force
Apolyton.FastJSON.Tests.dll
Apolyton.FastJson.dll
consoletest.exe
consoletest.vshost.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
Apolyton.FastJson.dll
consoletest.exe
fastJSON.dll
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
consoletest.exe
using System;
using System.Linq;
using Apolyton.FastJson;
using Apolyton.FastJson.Serialization;
using Apolyton.FastJson.Tests.Helpers;
using Apolyton.FastJson.TestsHelpers.StandardTypes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Apolyton.FastJson.Tests.Helpers.ComplexTypes;
using Apolyton.FastJson.Tests.Data.Helpers.StandardTypes;

namespace Apolyton.FastJson.Tests
{
    [TestClass]
    public class JsonObjectDeserializerTests
    {
        private JsonParameters CreateTestParameters()
        {
            return new JsonParameters()
            {
                UseUtcDateTime = true,
                UseExtensions = false,
                UsingGlobalTypes = false
            };
        }

        [TestMethod]
        public void JsonObjectDeserializer_Constructor()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
        }

        #region Deserialize Method Tests

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_IntClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Integer\":1,\"NullableInteger\":2}";

            var result = (IntClass)decoder.Deserialize(ref jsonString, typeof(IntClass));
            Assert.AreEqual(1, result.Integer);
            Assert.AreEqual(2, result.NullableInteger);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_GuidClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Guid\":\"523E0E25-0C24-421D-B738-D700E865F98D\",\"NullableGuid\":\"21DCC819-6F3D-4068-9AE7-3521896E5CFF\"}";

            var result = (GuidClass)decoder.Deserialize(ref jsonString, typeof(GuidClass));
            Assert.AreEqual(new Guid("523E0E25-0C24-421D-B738-D700E865F98D"), result.Guid);
            Assert.AreEqual(new Guid("21DCC819-6F3D-4068-9AE7-3521896E5CFF"), result.NullableGuid);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_UnsignedIntClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Integer\":" + uint.MaxValue.ToString() + ",\"NullableInteger\":2}";

            var result = (UnsignedIntClass)decoder.Deserialize(ref jsonString, typeof(UnsignedIntClass));
            Assert.AreEqual(uint.MaxValue, result.Integer);
            Assert.AreEqual((uint)2, result.NullableInteger);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_LongClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Long\":1,\"NullableLong\":2}";

            var result = (LongClass)decoder.Deserialize(ref jsonString, typeof(LongClass));
            Assert.AreEqual((long)1, result.Long);
            Assert.AreEqual((long)2, result.NullableLong);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_EnumClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Gender\":\"Male\"}";

            var result = (EnumClass)decoder.Deserialize(ref jsonString, typeof(EnumClass));

            Assert.AreEqual(Gender.Male, result.Gender);
        }


        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_TimeSpanClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"TimeSpan\":\"01:02:03\",\"NullableTimeSpan\":\"04:05:06\"}";

            var result = (TimespanClass)decoder.Deserialize(ref jsonString, typeof(TimespanClass));
            Assert.AreEqual(new TimeSpan(1, 2, 3), result.TimeSpan);
            Assert.AreEqual(new TimeSpan(4, 5, 6), result.NullableTimeSpan);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_UnsignedLongClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Long\":1,\"NullableLong\":2}";

            var result = (UnsignedLongClass)decoder.Deserialize(ref jsonString, typeof(UnsignedLongClass));
            Assert.AreEqual((ulong)1, result.Long);
            Assert.AreEqual((ulong)2, result.NullableLong);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_ShortClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Short\":1,\"NullableShort\":2}";

            var result = (ShortClass)decoder.Deserialize(ref jsonString, typeof(ShortClass));
            Assert.AreEqual((short)1, result.Short);
            Assert.AreEqual((short)2, result.NullableShort);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_UnsignedShortClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Short\":1,\"NullableShort\":2}";

            var result = (UnsignedShortClass)decoder.Deserialize(ref jsonString, typeof(UnsignedShortClass));
            Assert.AreEqual((ushort)1, result.Short);
            Assert.AreEqual((ushort)2, result.NullableShort);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_DoubleClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Double\":1,\"NullableDouble\":2}";

            var result = (DoubleClass)decoder.Deserialize(ref jsonString, typeof(DoubleClass));
            Assert.AreEqual(1, result.Double);
            Assert.AreEqual(2, result.NullableDouble);
        }

        [TestMethod]
        public void JsonObjectDeserializer_StringClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"String\":\"A\"}";

            var result = (StringClass)decoder.Deserialize(ref jsonString, typeof(StringClass));
            Assert.AreEqual("A", result.String);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_DateTimeClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"DateTime\":\"1955-03-04 09:22:33Z\",\"NullableDateTime\":\"1956-04-05 08:22:33Z\"}";

            var result = (DateTimeClass)decoder.Deserialize(ref jsonString, typeof(DateTimeClass));
            Assert.AreEqual(new DateTime(1955, 3, 4, 10, 22, 33), result.DateTime);
            Assert.AreEqual(new DateTime(1956, 4, 5, 10, 22, 33), result.NullableDateTime);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_ByteArrayClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"ByteArray\":\"AQID\",\"ByteEnumeration\":null}";

            var result = (ByteArrayClass)decoder.Deserialize(ref jsonString, typeof(ByteArrayClass));
            Assert.AreEqual(1, result.ByteArray[0]);
            Assert.AreEqual(2, result.ByteArray[1]);
            Assert.AreEqual(3, result.ByteArray[2]);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_ByteEnumerationClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"ByteArray\":null,\"ByteEnumeration\":\"AQID\"}";

            var result = (ByteArrayClass)decoder.Deserialize(ref jsonString, typeof(ByteArrayClass));
            Assert.IsTrue(new byte[] { 1, 2, 3 }.SequenceEqual(result.ByteEnumeration));
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_DictionaryClass()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Dictionary\":[{\"k\":1,\"v\":2},{\"k\":3,\"v\":5}]}";

            var result = (DictionaryClass<int, int>)decoder.Deserialize(ref jsonString, typeof(DictionaryClass<int, int>));
            Assert.AreEqual(2, result.Dictionary[1]);
            Assert.AreEqual(5, result.Dictionary[3]);
        }

        [TestMethod]
        public void JsonObjectDeserializer_Deserialize_Enumeration()
        {
            JsonObjectDeserializer decoder = new JsonObjectDeserializer(CreateTestParameters());
            String jsonString = "{\"Enumeration\":[1,2,3]}";

            var result = (EnumerableClass)decoder.Deserialize(ref jsonString, typeof(EnumerableClass));
            Assert.AreEqual((Int64)1, result.Enumeration.OfType<Object>().ElementAt(0));
            Assert.AreEqual((Int64)2, result.Enumeration.OfType<Object>().ElementAt(1));
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Aron Kovacs

Germany Germany
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 28 Aug 2013
Article Copyright 2012 by Aron Kovacs
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid