Beispiel #1
0
        /// <summary>Deserialize byte array to object. </summary>
        /// <param name="bytes">to read</param>
        /// <returns>object</returns>
        public static object ByteArrToObject(byte[] bytes)
        {
            if (bytes == null)
            {
                return(null);
            }

            return(SerializerFactory.Deserialize(
                       1,
                       bytes,
                       new[] { SerializerFactory.OBJECT_SERIALIZER })[0]);
        }
        public void TestTypes()
        {
            object[] expected = { 2, 3L, 4f, 5.0d, "abc", new byte[] { 10, 20 }, (byte)20, (short)21, true, new MyBean("E1") };
            var      classes  = new Type[expected.Length];

            for (var i = 0; i < expected.Length; i++)
            {
                classes[i] = expected.GetType();
            }

            var serializers = SerializerFactory.GetSerializers(classes);
            var bytes       = SerializerFactory.Serialize(serializers, expected);

            var result = SerializerFactory.Deserialize(expected.Length, bytes, serializers);

            EPAssertionUtil.AssertEqualsExactOrder(expected, result);

            // null values are simply not serialized
            bytes = SerializerFactory.Serialize(new[] { SerializerFactory.GetSerializer(typeof(int?)) }, new object[] { null });
            Assert.AreEqual(0, bytes.Length);
        }