Skip to content

ExNexu/spray-json-annotation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.6"
)

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0-M5" 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

Version history

0.6

  • Add support for final case class

0.5

  • Update dependency and plugin versions

0.4

  • First stable release

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

About

kifi/json-annotation for spray

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages