morgaroth / spray-json-annotation   0.4.2

MIT License GitHub

kifi/json-annotation for spray

Scala versions: 2.11 2.10


Build Status Coverage Status

Scala macro annotations generating spray-json JsonFormats for case classes.

Get started

Add this to your build.sbt (for Scala 2.10 & 2.11):

resolvers += " releases" at ""

libraryDependencies ++= Seq(
  "us.bleibinha" %% "spray-json-annotation" % "0.4"

addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)

Use it in code:

import spray.json._
import spray.json.DefaultJsonProtocol._
import us.bleibinha.spray.json.macros._

case class User(name: String, password: String)

This will be generated by the compiler:

case class User(name: String, password: String)

object User {
  implicit val jsonAnnotationFormat: RootJsonFormat[User] = jsonFormat2(User.apply)

@json can be used if the case class has only one field and you don't want to generate a full-blown json object. For more usage examples see the test implementation: JsonFormatAnnotationTest.scala


Code base from kifi/json-annotation which provides json annotations for play-json. More information on their blog:

This implements the same annotiations but with spray/spray-json as the underlying Scala json library.


MIT License