Tutorials     About     RSS
Tech and Media Labs

RionObjectReader

Jakob Jenkov
Last update: 2020-01-21

The RION Ops RionObjectReader class can read a RION Object field into a Java object. In other words, the RionObjectReader can deserialize RION into Java objects. In this RionObjectReader tutorial I will explain how to use the RION Ops RionObjectReader.

Create a RionObjectReader

To use the RionObjectReader you must first create an instance of it. The easiest way to create an instance of the RionObjectReader is via the RionObjectReaderBuilder class. This class makes it easier to configure and create a RionObjectReader instance. Here is an example of creating a RionObjectReader via the RionObjectReaderBuilder class:

RionObjectReaderBuilder readerBuilder = new RionObjectReaderBuilder();

readerBuilder.setTypeClass(Pojo.class);
readerBuilder.addDeclaredFieldsForTypeClass();

RionObjectReader reader = readerBuilder.build();

The RionObjectReaderBuilder is designed for "method chaining", so the above code could be written a bit clearer like this:

RionObjectReader reader =
        new RionObjectReaderBuilder()
            .setTypeClass(Pojo.class)
            .addDeclaredFieldsForTypeClass()
            .build();

Read an Object

To read a Java object via the RionObjectReader you must first have a RION Object field stored in a Java byte array. Once you have that, you can read that RION Object field via the RionObjectReader. Here is an example that first writes a Pojo instance as RION into a Java byte array, and then reads it into a Java object again:

Pojo pojo = new Pojo();


RionObjectWriterBuilder writerBuilder = new RionObjectWriterBuilder();
writerBuilder.addDeclaredFields(Pojo.class);
RionObjectWriter writer = writerBuilder.build();

byte[] data = new byte[1024];
int bytesWritten = writer.writeObject(pojo, 2, data, 0);


RionObjectReaderBuilder readerBuilder = new RionObjectReaderBuilder();
readerBuilder.setTypeClass(Pojo.class);
readerBuilder.addDeclaredFieldsForTypeClass();
RionObjectReader reader = readerBuilder.build();

Pojo pojoRead = (Pojo) reader.read(data, 0);

Jakob Jenkov

Right 1
Right 2
Close TOC

All Trails

Trail TOC

Page TOC

Previous

Next