Skip to content

Instantly share code, notes, and snippets.

@paradoja
Created June 6, 2017 10:03
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 paradoja/c55d1f5aec24f841ce5725f68529f622 to your computer and use it in GitHub Desktop.
Save paradoja/c55d1f5aec24f841ce5725f68529f622 to your computer and use it in GitHub Desktop.
import shapeless._, syntax.std.product._, spray.json.{JsNumber, JsString}
case class Person(name: String, age: Int)
val p = Person("Pepe", 54)
p.toMap[Symbol, Any] // res0: Map[Symbol,Any] = Map('age -> 54, 'name -> Pepe)
p.toMap[Symbol, Any].map {
case (s, i: Int) => s.toString -> JsNumber(i)
case (s, x: Any) => s.toString -> JsString(x.toString)
} // res1: Map[String,Product with Serializable with spray.json.JsValue] = Map('age -> 54, 'name -> "Pepe")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment