I am using Avro serialiser to push messages to kafka topic. I generated the Java class out of the below avro schema
{
"type": "record",
"name": "CommonHeader",
"fields": [
{
"name": "domain",
"type": "string"
},
{
"name": "eventSource",
"type": "string"
},
{
"name": "eventEntity",
"type": "string"
},
{
"name": "eventType",
"type": "string"
},
{
"name": "tsEventPublished",
"type": "string"
},
{
"name": "tsEntityCreated",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "tsEntityUpdated",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "isSynthetic",
"type": [
"boolean"
],
"default": false
},
{
"name": "correlationId",
"type": "string"
}
]
}
The generated class is attached here.CommonHeader.java
When I write the message to kafka, the message looks like this
"domain": "product",
"eventSource": "source",
"eventEntity": "entity",
"eventType": "Create",
"tsEventPublished": "2021-11-04T02:39:42.261Z",
"tsEntityCreated": {
"string": "2021-11-21T21:25:04.000Z"
},
"tsEntityUpdated": {
"string": "2011-11-04T00:11:52.000Z"
},
"isSynthetic": {
"boolean": false
},
"correlationId": "id"
}
why are the values of "isSynthetic" and "tsEntityUpdated" are nested? How can I avoid this?
Spring boot properties for kafka:
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=io.confluent.kafka.serializers.KafkaAvroSerializer
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=io.confluent.kafka.serializers.KafkaAvroDeserializer
spring.kafka.consumer.auto-offset-reset=latest
spring.kafka.properties.auto.register.schemas=false
spring.kafka.properties.specific.avro.reader=true
Plugin info:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<id>schemas</id>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
<goal>protocol</goal>
<goal>idl-protocol</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>