Kafkatemplate send NPE

Hi there… I am using avro to tell schema registry about the type of data I sent to confluent cluster. Out of them few values hold nulls. While sending the data to topic, it just throws null pointer exception… at datumwriter.writeasstring method Can someone help…how to put data into topic though it has some null vales

Hi @Saiteja3963 , welcome to the forum!

Please can you give a bit more detail, such as the relevant except from the code that you’re running?

Hi, I have defined a avro schema file from which I have created the avro classes using avro plugin. Let’s say I have one string feild and one array of user defined objects. I have also defined default value as null for all members. So when I send this avro object to a topic using kafkatemplate… I am receiving a null pointer exception because few of the parameters have null as their values. During serialisation, the helper code which is DatumWriter is trying to make the avro object as string. As some feilds are null… It is exiting with a npe. And event is unable to publish to topic. Is ther any way we can put data into topic where the data can have null values.

Please can you share the code that you’re running. It’s hard for people to help otherwise :slight_smile:

Sure rmoff. Here is a sample:

{
   "type" : "record",
   "namespace" : "com.test.kafka",
   "name" : "Employee",
   "fields" : [
      { "name" : "Name" , "type" : ["string","null"], "default": null },
      { "name" : "Age" , "type" : "int" }
   ]
}

Lets say this is avro class that I need to put into kafka for every kafkatemplate.send.

For instance, if I set the name as null and push it to kafka… I am getting a null pointer exception while serializing it.
Class is somewhere like DatumWriter.writeValueasString
Can you please help resolve it.
Hope it clarifies!