romansky / jello

Scala/Scala.js JSON library, no thrills included

GitHub

jello

Build Status Scala.js Maven Central

http://search.maven.org/#artifactdetails|com.uniformlyrandom|jello_2.11|0.3.0|jar

Scala.js & JVM JSON marshalling library with straightforward format.

Why did I create yet another JSON library?

Scala.js prohibits dynamically invoked code, so one has to use macros where one would otherwise use mechanisms such as reflection etc.

At the same time, the Scala.js community created some idiomatic marshaling/pickling libraries which were a divergence from the common. (Play Framework etc..) As it turned out, if one wants to use one of these generic libraries on the back-end he could not use any of the existing Scala-js compatible JSON libraries.

Thus Jello was born.

Usage

Installation

libraryDependencies ++= Seq("com.uniformlyrandom" %%% "jello" % "0.3.0)

Overview

Jello takes inspiration from Play Json, the formatters need to be provided implicitly, it's recommended to have the companion object contain these formatters

case class A (
    m1: String,
    m2: Int
)

object A {
    implicit fmt: JelloFormat[A] = JelloFormat.format[A]
}

object App {

    import com.uniformlyrandom.jello.TypesLibrary._

    def main(args: Array[String]): Unit = {
        val a: A = A("value",1)
        val aJV: JelloValue = JelloJson.toJson(a)
        val aJson: String = JelloJson.toJsonString(aJV)
        //aJson == {"m1":"value","m2":1}
        val ajJV: JelloValue = JelloJson.parse(aJson)
        val aTry: Try[A] = JelloJson.fromJson(ajJV)
        
        assert(Try(a) == aTry)
    }
}

Supported features

  • Enumerations support
  • helper constructs to serialize traits