fommil / spray-json-shapeless

:sparkles: Shapeless JsonFormats for spray-json

GitHub

spray-json-shapeless

THIS PROJECT IS NO LONGER MAINTAINED, PLEASE PREFER CIRCE

Automatically derive spray-json JsonFormats, powered by shapeless (no macros were written during the creation of this library).

For documentation, read the scaladocs and for examples read the test cases.

Please read the documentation - especially the caveats - and examples before raising a ticket.

TL;DR

// always check maven central for the lastest release
libraryDependencies += "com.github.fommil" %% "spray-json-shapeless" % "1.4.0"
import spray.json._
import fommil.sjs.FamilyFormats._

object domain {
  sealed trait SimpleTrait
  case class Foo(s: String) extends SimpleTrait
  case class Bar() extends SimpleTrait
  case object Baz extends SimpleTrait
  case class Faz(o: Option[String]) extends SimpleTrait
}
object use {
  import domain._

  Foo("foo").toJson                // """{"s":"foo"}"""
  Faz(Some("meh")).toJson          // """{"o":"meh"}"""
  Faz(None).toJson                 // """{}"""
  (Foo("foo"): SimpleTrait).toJson // """{"type":"Foo","s":"foo"}"""
  (Bar(): SimpleTrait).toJson      // """{"type":"Bar"}"""
  (Baz: SimpleTrait).toJson        // """{"type":"Baz"}"""
  (Faz(None): SimpleTrait).toJson  // """{"type":"Faz"}"""
}