Greetings,
I've poked around for examples of this, but I can't find any. I
imagine it's a fairly common use case.
I'm serializing some simple objects into bytes for placement onto
RabbitMQ. My java class is pretty simple (but it'll grow in complexity
in time).:
{
String[] Columns;
}
So, I made a .json schema containing this:
{
"namespace": "com.dts",
"name": "QueueItem",
"type": "record",
"fields": [
{"name": "Columns", "type": ["null", {"type": "array",
"items":"string"}]}
]
}
And generated a java class ...
Now, I'm writing a test to serialize and deserialize some items. I can
figure out the serialization, but not deserialization back to objects.
Schema s = Schema.parse(new File("queuetype.json"));
ByteArrayOutputStream bao = new ByteArrayOutputStream();
GenericDatumWriter w = new GenericDatumWriter(s);
Encoder e = new BinaryEncoder(bao);
e.init (bao);
QueueItem r = new QueueItem();
r.put(0, items);
w.write(r, e);
e.flush();
ByteArrayInputStream is = new
ByteArrayInputStream(bao.toByteArray());
DecoderFactory df = new DecoderFactory();
Decoder d = df.createBinaryDecoder(is, null);
QueueItem itemout = (QueueItem) .....
And that's what I can't figure out -- how do I use a decoder method to
create QueueItems?
Cheers,
B
radford Stephens,
Founder, Drawn to Scale
drawntoscalehq.com
727.697.7528
http://www.drawntoscalehq.com -- The intuitive, cloud-scale data
solution. Process, store, query, search, and serve all your data.
http://www.roadtofailure.com -- The Fringes of Scalability, Social
Media, and Computer Science