Skip to content

Instantly share code, notes, and snippets.

@joshcough
Created May 23, 2015 01:52
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 joshcough/4cb4f415001f0bf517c4 to your computer and use it in GitHub Desktop.
Save joshcough/4cb4f415001f0bf517c4 to your computer and use it in GitHub Desktop.
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