morgaroth / spray-json-annotation   0.4.2

MIT License GitHub

kifi/json-annotation for spray

Scala versions: 2.11 2.10

spray-json-annotation

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 += "bleibinha.us/archiva releases" at "http://bleibinha.us/archiva/repository/releases"

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._

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

This will be generated by the compiler:

@jsonstrict
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

Background

Code base from kifi/json-annotation which provides json annotations for play-json. More information on their blog: http://eng.kifi.com/scala-macro-annotations-real-world-example/

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

License

MIT License