adambaker / spray-json-annotation   0.1.0

MIT License GitHub

The quickest way to add a Format instance to your spray-json case class

Scala versions: 2.12 2.11

The @json scala macro annotation is the quickest way to add a spray.json.RootJsonFormat to your case classes.

How it works

Just add @json in front of your case class definition:

import us.logico_philosophic.macros.json

@json case class Person(name: String, age: Int)

You can now serialize/deserialize your objects:

import spray.json.{enrichAny, enrichString}

val person = Person("Victor Hugo", 46)
val json = person.toJson
json.convertTo[Person]

Installation

Add the following settings to your build:

libraryDependencies += "us.logico-philosophic" %% "spray-json-annotation" % "0.1.0"

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

This library was tested with both Scala 2.11 and 2.12.