How not to serialize binary data:

import io.circe._

final case class Message(body: ByteString)

object Message {
  implicit val encodeMessage: Encoder[Message] =
    Encoder.instance { message =>
      val array = message.body.toByteArray

Sadly, I actually saw this today… I didn’t do a git blame; I guess I’d never be able to look at that person again 😢


TIL that you can declare a (case) class in a method body. In other words the following is valid Scala code:

def foo(s: String): Unit = {
  final case class Foo(i: Int)

Even after six years Scala continues to surprise.