1 package de.juplo.kafka;
3 import com.fasterxml.jackson.core.JsonGenerator;
4 import com.fasterxml.jackson.databind.JsonSerializer;
5 import com.fasterxml.jackson.databind.SerializerProvider;
6 import lombok.extern.slf4j.Slf4j;
7 import org.apache.kafka.common.TopicPartition;
9 import java.io.IOException;
13 public class PartitionStatisticsSerializer extends JsonSerializer<PartitionStatistics>
16 public Class<PartitionStatistics> handledType()
18 return PartitionStatistics.class;
22 public void serialize(
23 PartitionStatistics statistics,
24 JsonGenerator jsonGenerator,
25 SerializerProvider serializerProvider) throws IOException
27 jsonGenerator.writeStartObject();
34 jsonGenerator.writeNumberField(counter.getKey(), counter.getResult());
36 catch (NumberFormatException | IOException e)
38 log.error("Could not write {}: {}", counter, e.toString());
41 jsonGenerator.writeEndObject();