Created
June 6, 2017 10:03
-
-
Save paradoja/c55d1f5aec24f841ce5725f68529f622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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