Search in sources :

Example 1 with JsonJacksonMessageSerDe

use of com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe in project chassis by Kixeye.

the class ScalaCaseClassTest method testJsonSerDe.

@Test
public void testJsonSerDe() throws Exception {
    final JsonJacksonMessageSerDe serDe = new JsonJacksonMessageSerDe();
    final TestObject obj = new TestObject(RandomStringUtils.randomAlphanumeric(64), new SomeOtherObject(RandomStringUtils.randomAlphanumeric(64)));
    final byte[] serializedObj = serDe.serialize(obj);
    dumpToLog(serDe, serializedObj);
    final TestObject deserializedObj = serDe.deserialize(serializedObj, 0, serializedObj.length, TestObject.class);
    Assert.assertEquals(obj, deserializedObj);
}
Also used : JsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe) Test(org.junit.Test)

Example 2 with JsonJacksonMessageSerDe

use of com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe in project chassis by Kixeye.

the class SerDeTest method testSerDes.

@Test
public void testSerDes() throws Exception {
    for (MessageSerDe serDe : Lists.newArrayList(new BsonJacksonMessageSerDe(), new JsonJacksonMessageSerDe(), new ProtobufMessageSerDe(), new XmlMessageSerDe(), new YamlJacksonMessageSerDe())) {
        logger.info("Testing SerDe: [{}], for serialization of: [{}]", serDe.getClass().getSimpleName(), serDe.getMessageFormatName());
        TestObject testObject = TestObject.generateRandom(1, true);
        logger.info("Generated test object for serialization: [{}]", testObject);
        // serialize object
        byte[] serializedTestObject = serDe.serialize(testObject);
        dumpBytes(serializedTestObject);
        // test deserialization
        Assert.assertEquals(testObject, serDe.deserialize(serializedTestObject, 0, serializedTestObject.length, TestObject.class));
        Assert.assertEquals(testObject, serDe.deserialize(new ByteArrayInputStream(serializedTestObject), TestObject.class));
        // serialize object
        ByteArrayOutputStream serializedTestObjectStream = new ByteArrayOutputStream();
        serDe.serialize(testObject, serializedTestObjectStream);
        serializedTestObject = serializedTestObjectStream.toByteArray();
        dumpBytes(serializedTestObject);
        // test deserialization
        Assert.assertEquals(testObject, serDe.deserialize(serializedTestObject, 0, serializedTestObject.length, TestObject.class));
        Assert.assertEquals(testObject, serDe.deserialize(new ByteArrayInputStream(serializedTestObject), TestObject.class));
    }
}
Also used : XmlMessageSerDe(com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe) JsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe) YamlJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe) XmlMessageSerDe(com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe) BsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe) ProtobufMessageSerDe(com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe) ProtobufMessageSerDe(com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) YamlJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe) BsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe) Test(org.junit.Test)

Aggregations

JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)2 Test (org.junit.Test)2 BsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe)1 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)1 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)1 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1