Skip to content

Instantly share code, notes, and snippets.

@debasishg
Forked from dcsobral/gist:4698349
Last active December 12, 2015 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debasishg/4698878 to your computer and use it in GitHub Desktop.
Save debasishg/4698878 to your computer and use it in GitHub Desktop.
// At the external API level, use TypeTag
def extract[T: TypeTag](jsv: JsValue): T =
extractImpl[T](jsv, typeOf[T])
// But use Type for everything else
def extractImpl[T](jsv: JsValue, tpe: Type): T = {
// no need for m
val ex = jsv match {
case JsNumber(n) => n
case JsString(s) => s
case JsArray(l) => {
// deep serialization
val intpe = tpe.typeSymbol.asType.typeParams.head.asType.toTypeIn(tpe)
l.map(in(_, intpe))
}
//..
}
}
def in[T](js: JsValue, tpe: Type): T = {
// no need for m
//..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment