Skip to content

Instantly share code, notes, and snippets.

@dcsobral
Created February 2, 2013 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dcsobral/4698349 to your computer and use it in GitHub Desktop.
Save dcsobral/4698349 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 = m.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