Skip to content

Instantly share code, notes, and snippets.

@leosilvadev
Created October 23, 2019 02:59
Show Gist options
  • Save leosilvadev/ce4452616d0651ad0995d5ca6ebd277e to your computer and use it in GitHub Desktop.
Save leosilvadev/ce4452616d0651ad0995d5ca6ebd277e to your computer and use it in GitHub Desktop.
import com.sksamuel.avro4s.{AvroSchema, SchemaFor}
import org.apache.avro.Schema
import org.apache.avro.util.Utf8
case class MyClass(id: Utf8, name: Utf8, familyName: Option[Utf8])
object Main extends App {
implicit object Utf8Schema extends SchemaFor[Utf8] {
override def schema: Schema = Schema.create(Schema.Type.STRING)
}
implicit object OptionUtf8Schema extends SchemaFor[Option[Utf8]] {
override def schema: Schema = Schema.createUnion(Schema.create(Schema.Type.NULL), Schema.create(Schema.Type.STRING))
}
val schema = AvroSchema[MyClass]
println(schema)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment