Search in sources :

Example 1 with RiverUnmarshaller

use of org.jboss.marshalling.river.RiverUnmarshaller in project eap-additional-testsuite by jboss-set.

the class MarshallingTestCase method deserializationTest.

@ATTest({ "modules/testcases/jdkAll/Wildfly/core/src/main/java#10.0.0.Final*11.0.0.Beta1" })
public void deserializationTest() throws Exception {
    RiverMarshallerFactory factory = new RiverMarshallerFactory();
    MarshallingConfiguration configuration = new MarshallingConfiguration();
    configuration.setVersion(2);
    // Create a marshaller on some stream we have
    RiverMarshaller marshaller = (RiverMarshaller) factory.createMarshaller(configuration);
    final ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream();
    marshaller.start(new OutputStreamByteOutput(fileOutputStream));
    Bar bar = new Bar("Hello");
    Foo foo = new Foo(bar);
    // Write lots of stuff
    marshaller.writeObject(foo);
    // Done
    marshaller.finish();
    RiverUnmarshaller unmarshaller = (RiverUnmarshaller) factory.createUnmarshaller(configuration);
    ByteArrayInputStream fileInputStream = new ByteArrayInputStream(fileOutputStream.toByteArray());
    unmarshaller.start(new InputStreamByteInput(fileInputStream));
    try {
        Foo f = unmarshaller.readObject(Foo.class);
        Assert.assertEquals(f.bar.aString, "Hello");
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
    unmarshaller.finish();
}
Also used : RiverUnmarshaller(org.jboss.marshalling.river.RiverUnmarshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) RiverMarshallerFactory(org.jboss.marshalling.river.RiverMarshallerFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RiverMarshaller(org.jboss.marshalling.river.RiverMarshaller) ATTest(org.jboss.eap.additional.testsuite.annotations.ATTest)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)1 InputStreamByteInput (org.jboss.marshalling.InputStreamByteInput)1 MarshallingConfiguration (org.jboss.marshalling.MarshallingConfiguration)1 OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)1 RiverMarshaller (org.jboss.marshalling.river.RiverMarshaller)1 RiverMarshallerFactory (org.jboss.marshalling.river.RiverMarshallerFactory)1 RiverUnmarshaller (org.jboss.marshalling.river.RiverUnmarshaller)1