christian-schlichtherle / circe-kafka   3.0.0

Apache License 2.0 GitHub

Implicit conversion of Encoder/Decoder/Codec to Serializer/Deserializer/Serde.

Scala versions: 3.x 2.13 2.12

Release Notes Maven Central Apache License 2.0 Test Workflow

Circe-Kafka

Provides an implicit conversion from Circe's Encoder, Decoder and Codec types to Kafka's Serializer, Deserializer and Serde types so that you can (de)serialize your data from/to JSON format.

This fork is based on original work by Tim Steinbach - kudos to you! It has been primarily created to add support for value classes, e.g. Serde[A] forSome { type A <: AnyVal }. It also updates dependencies, improves test coverage and is cross-compiled for Scala 2.12, 2.13 and 3.

Artifact

libraryDependencies ++= "global.namespace.circe-kafka" %% "circe-kafka" % "3.0.0"

Note that this library attempts to match the Kafka version.

Usage

// Given:

import io.circe.generic.auto._
import org.apache.kafka.common.serialization._

case class Entity(id: Long)

// When:

import global.namespace.circe.kafka._

val serde: Serde[Foo] = implicitly

import serde._

val bytes = serializer.serialize("some-topic", Entity(1))
val clone = deserializer.deserialize("some-topic", bytes)

// Then:

assert(new String(bytes, "UTF-8") == """{"id":1}""") // look Ma', JSON!
assert(clone == Entity(1))