io.github.productboardlabs.kafka.serializers.DefaultJacksonKafkaAvroSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-kafka-avro-serializer Show documentation
Show all versions of jackson-kafka-avro-serializer Show documentation
Kafka Avro (de)serializer using Apache Jackson
The newest version!
package io.github.productboardlabs.kafka.serializers;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import static io.github.productboardlabs.kafka.serializers.Utils.parseSchema;
public class DefaultJacksonKafkaAvroSerializer extends AbstractJacksonKafkaAvroSerializer {
private boolean isKey;
@Override
public void configure(Map configs, boolean isKey) {
super.configure(configs, isKey);
this.isKey = isKey;
}
@Override
@NotNull
protected SchemaMetadata getSchemaFor(@NotNull String topic, @NotNull Object object) {
String subjectName = getSubjectName(topic, isKey, object, null);
return new SchemaMetadata(parseSchema(getPath(topic, object, subjectName)), subjectName);
}
@NotNull
protected String getPath(@NotNull String topic, @NotNull Object value, @NotNull String subjectName) {
return "avro_schemas/" + subjectName + ".avsc";
}
}