Skip to content

Instantly share code, notes, and snippets.

@robertberry-zz
Created August 28, 2014 13:38
Show Gist options
  • Save robertberry-zz/e4e9d57fd4eee0e6e505 to your computer and use it in GitHub Desktop.
Save robertberry-zz/e4e9d57fd4eee0e6e505 to your computer and use it in GitHub Desktop.
sealed trait Foo
case class Bar(a: Int) extends Foo
case class Baz(b: Int) extends Foo
object FooJson {
def fromFoo(foo: Foo) = foo match {
case Bar(a) => FooJson("bar", Some(a), None)
case Baz(b) => FooJson("baz", None, Some(b))
}
}
case class FooJson(
`type`: String,
a: Option[Int],
b: Option[Int]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment