I've stopped doing scala, so this project is not going anywhere. feel free to adopt it
A library for macro based serializers to different formats. It uses scala macros so no reflection is involved and it will generate code at compile time that kind of looks like it would have been handwritten. It is written with the idea of extension, so it's easy to add your own formats.
You can find the documentation on the site
This works with scala 2.10 and up. The library is published to maven central so you can get it with:
libraryDependencies += "org.json4s" %% "muster-codec-jawn" % "0.3.0"
libraryDependencies += "org.json4s" %% "muster-codec-jackson" % "0.3.0"
Bring your own AST (BYA):
For Json4s:
libraryDependencies += "org.json4s" %% "muster-codec-json4s" % "0.3.0"
For Play Json:
libraryDependencies += "org.json4s" %% "muster-codec-play-json" % "0.3.0"
For Argonaut:
libraryDependencies += "org.json4s" %% "muster-codec-argonaut" % "0.3.0"
Prettier case class for debugging:
libraryDependencies += "org.json4s" %% "muster-codec-string" % "0.3.0"
You can find the documentation on the site The idea is that things work a little bit like this:
case class Person(id: Long, name: String, age: Int)
val person = Person(1, "Luke", 38)
import muster.codec.jawn._
JsonFormat.from(person)
JsonFormat.into(new File("luke.json")).from(person)
JsonFormat.Pretty.from(person)
import muster.codec.jawn.api._
person.asJson // calls: JsonFormat.from(person) and produces {"id":1,"name":"Luke","age":38}
person.asPrettyJson /* calls: JsonFormat.Pretty.from(person) and produces
{
"id":1,
"name":
"Luke",
"age":38
} */
import muster.codec.json4s._
// decompose to a Json4s AST
Json4sFormat.from(person)
import muster.codec.json4s.api._
person.asJValue
// Serialize Json4s AST's
import muster.codec.json4s.api._
JsonFormat.into(new File("jvalues.json")).from(person.asJValue)
JsonFormat.Pretty.from(person.asJValue)
// Prettier string formatting of case classes
import muster.codec.string._
StringFormat.from(person)
import muster.codec.string.api._
person.asString
// calls muster.codec.string.api.StringFormat.from(person)
// and produces Person(id: 1, name: "Luke", age: 38)
Similarly reading can be achieved with
// Extract a person from a json stream
import muster.codec.jawn._
JsonFormat.as[Person](/* file | string | reader | byte array | input stream | URL */ input)
// Extract a person from a Json4s AST
import muster.codec.json4s._
JValueFormat.as[Person](personJValue)
// Parse a source to a Json4s AST
import muster.codec.json4s._
JsonFormat.as[JValue](/* file | string | reader | byte array | input stream | URL */ input)
Seamless integration with the Json4s AST, it can be used to extract objects from and decompose objects to json4s AST's. It can be used to parse Json4s AST's
Currently muster supports JSON through parsing with jackson or jawn and it can extract the following things:
Object mapping features:
Possibly added next: