java - NullPointerException in Avro ReflectDatumWriter -



java - NullPointerException in Avro ReflectDatumWriter -

i have specific issue avro serialization of java objects. have pojo's generated xsd schemas trying serialize using avro place on kafka topic. of xmlelements optional

a test message looks this:

@xmlrootelement(name = "message") public class testmessage { @xmlelement public string id; @xmlelement public string name; public testmessage(string id, string name) { this.id = id; this.name = name; } public testmessage() { } @override public string tostring() { homecoming "message{" + "id='" + id + '\'' + ", name=" + name + '}'; } }

and method serialize , place on topic is:

public void sendmessage(testmessage msg) throws exception{ datumwriter<testmessage> author = new reflectdatumwriter<testmessage>(testmessage.class); bytearrayoutputstream os = new bytearrayoutputstream(); encoder encoder = encoderfactory.get().binaryencoder(os, null); writer.write(msg, encoder); encoder.flush(); os.close(); keyedmessage<string, byte[]> info = new keyedmessage<string, byte[]>(topic_name, os.tobytearray()); producer.send(data); }

when send both fields works expected. if null 1 of fields or leave out npe's write.

java.lang.nullpointerexception: in testmessage in string null of string in field id of testmessage @ org.apache.avro.reflect.reflectdatumwriter.write(reflectdatumwriter.java:145) @ org.apache.avro.generic.genericdatumwriter.write(genericdatumwriter.java:58)

any ideas? or point me in right direction

thanks!

it appear ended managing solve myself after posting, couple days of reading internets later

reflectdata reflectdata = reflectdata.allownull.get(); schema schema = reflectdata.getschema(testmessage.class); datumwriter<testmessage> author = new reflectdatumwriter<testmessage>(schema);

appears allow utilize of nulls quite happily.

on next error! is

org.apache.avro.unresolvedunionexception: not in union ["null",{"type":"record","name":"xmlgregoriancalendar","namespace":"javax.xml.datatype","fields":[]}]: 2014-10-22 @ org.apache.avro.generic.genericdata.resolveunion(genericdata.java:604) @ org.apache.avro.generic.genericdatumwriter.resolveunion(genericdatumwriter.java:151) @ org.apache.avro.generic.genericdatumwriter.write(genericdatumwriter.java:71) @ org.apache.avro.reflect.reflectdatumwriter.write(reflectdatumwriter.java:143) @ org.apache.avro.generic.genericdatumwriter.writefield(genericdatumwriter.java:114)

java serialization reflection avro

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -