public void TestTypes() { Object[] expected = new Object[] { 2, 3L, 4f, 5.0d, "abc", new byte[] { 10, 20 }, (byte)20, (short)21, true, new MyBean("E1") }; Type[] classes = new Type[expected.Length]; for (int i = 0; i < expected.Length; i++) { classes[i] = expected.GetType(); } Serializer[] serializers = SerializerFactory.GetSerializers(classes); byte[] bytes = SerializerFactory.Serialize(serializers, expected); Object[] result = SerializerFactory.Deserialize(expected.Length, bytes, serializers); EPAssertionUtil.AssertEqualsExactOrder(expected, result); // null values are simply not serialized bytes = SerializerFactory.Serialize(new Serializer[] { SerializerFactory.GetSerializer(typeof(int)) }, new Object[] { null }); Assert.AreEqual(0, bytes.Length); }
/// <summary>Serialize object to byte array. </summary> /// <param name="underlying">to serialize</param> /// <returns>byte array</returns> public static byte[] ObjectToByteArr(Object underlying) { return(SerializerFactory.Serialize( new[] { SerializerFactory.OBJECT_SERIALIZER }, new[] { underlying })); }