Skip to content

Instantly share code, notes, and snippets.

@josep2
Created November 22, 2019 03:06
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 josep2/46eb8a07fd73ab93c2f2db1de251e164 to your computer and use it in GitHub Desktop.
Save josep2/46eb8a07fd73ab93c2f2db1de251e164 to your computer and use it in GitHub Desktop.
// From https://github.com/spray/spray-json
case class Color(name: String, red: Int, green: Int, blue: Int)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val colorFormat = jsonFormat4(Color)
}
import MyJsonProtocol._
import spray.json._
val json = Color("CadetBlue", 95, 158, 160).toJson
val color = json.convertTo[Color]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment