Skip to content

Instantly share code, notes, and snippets.

@dcastro
Created April 27, 2018 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcastro/e3fe36057a6edf5e86369a011b7a9db9 to your computer and use it in GitHub Desktop.
Save dcastro/e3fe36057a6edf5e86369a011b7a9db9 to your computer and use it in GitHub Desktop.
Circe + Shapeless: blacklist fields with type-safety
import shapeless._, record._
import io.circe._
import io.circe.syntax._
import io.circe.generic.encoding._
case class Person(name: String, age: Int)
object Person {
implicit val encodePerson: Encoder[Person] =
ReprObjectEncoder.deriveReprObjectEncoder.contramap { person =>
LabelledGeneric[Person].to(person) - 'age
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment