Skip to content
/ jello Public

Scala/Scala.js JSON library, no thrills included

License

Notifications You must be signed in to change notification settings

romansky/jello

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jello

Build Status Scala.js Maven Central

http://search.maven.org/#artifactdetails|com.uniformlyrandom|jello_2.13|1.0.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" % "1.0.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

About

Scala/Scala.js JSON library, no thrills included

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages