Skip to content

Instantly share code, notes, and snippets.

@maheshkelkar
Last active October 23, 2015 18:54
Show Gist options
  • Save maheshkelkar/df3049d98f4c20a9f691 to your computer and use it in GitHub Desktop.
Save maheshkelkar/df3049d98f4c20a9f691 to your computer and use it in GitHub Desktop.
Circe Encoder Decoder question
import com.twitter.finagle.httpx.Method
import com.twitter.finagle.httpx.path.Path
import cats.data.Xor
import io.circe.Json.JString
import io.circe.{Encoder, _}
import io.circe.jawn._
import io.circe.generic.auto._
case class Foo(method: Option[com.twitter.finagle.httpx.Method])
val foo1 = Foo(Some(Method.Get))
val foo2 = Foo(None)
val f1json = foo1.asJson
val f2json = foo2.asJson
implicit val encodeMethod: Encoder[Method] = Encoder[String].contramap(_.toString)
implicit val decodeMethod: Decoder[Method] = Decoder[String].map(Method(_))
val f1EncodeDecode = decode[Foo](f1json.toString)
val f2EncodeDecode = decode[Foo](f2json.toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment