Muster by json4s

Fast serialization for classes in scala


Build Status

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

Getting the library

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"

How does it work?

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.into(new File("luke.json")).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
                       } */

import muster.codec.json4s._
// decompose to a Json4s AST

import muster.codec.json4s.api._

// Serialize Json4s AST's
import muster.codec.json4s.api._
JsonFormat.into(new File("jvalues.json")).from(person.asJValue)

// Prettier string formatting of case classes
import muster.codec.string._

import muster.codec.string.api._
// 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._[Person](/* file | string | reader | byte array | input stream | URL */ input)

// Extract a person from a Json4s AST
import muster.codec.json4s._[Person](personJValue)

// Parse a source to a Json4s AST
import muster.codec.json4s._[JValue](/* file | string | reader | byte array | input stream | URL */ input)

What's inside?

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: