Created
May 23, 2015 01:52
-
-
Save joshcough/4cb4f415001f0bf517c4 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 spray.json._ | |
import DefaultJsonProtocol._ | |
case class Color(name: String, red: Int, green: Int, blue: Int) | |
object MyJsonProtocol extends DefaultJsonProtocol { | |
implicit val colorFormat = jsonFormat4(Color) | |
} | |
object Main { | |
import MyJsonProtocol._ | |
import spray.json._ | |
val json = Color("CadetBlue", 95, 158, 160).toJson | |
def main(args: Array[String]): Unit = { | |
println(List( | |
("json", json) | |
,("json.convertTo[Color]", json.convertTo[Color]) | |
,("round-trip", json.convertTo[Color].toJson) | |
,("round-trip equality", json.convertTo[Color].toJson == json) | |
).mkString("\n", "\n\n", "\n")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment