Skip to content

Instantly share code, notes, and snippets.

@clayrat
Created April 23, 2015 15:42
Show Gist options
  • Save clayrat/3ec844fc22a9f68758b2 to your computer and use it in GitHub Desktop.
Save clayrat/3ec844fc22a9f68758b2 to your computer and use it in GitHub Desktop.
import argonaut._, Argonaut._, Shapeless._
object Tool {
trait Enum {
type EnumVal <: Value
protected trait Value { self: EnumVal =>
val name: String
}
}
object BarEnum extends Enum {
sealed trait EnumVal extends Value
val BarA = new EnumVal { val name = "A" }
val BarB = new EnumVal { val name = "B" }
val BarC = new EnumVal { val name = "C" }
}
final case class Foo(barEnum: Option[BarEnum.EnumVal])
def main(args: Array[String]) {
implicit def BarEnumValEncodeJson: EncodeJson[BarEnum.EnumVal] =
EncodeJson((s: BarEnum.EnumVal) => jString(s.name))
val fooEncoder = implicitly[EncodeJson[Foo]]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment