https://github.com/romansky/jello
Scala/Scala.js JSON library, no thrills included
https://github.com/romansky/jello
formatter json json-library marshalling scala
Last synced: 5 months ago
JSON representation
Scala/Scala.js JSON library, no thrills included
- Host: GitHub
- URL: https://github.com/romansky/jello
- Owner: romansky
- License: mit
- Created: 2015-12-29T20:04:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-02T12:21:07.000Z (over 2 years ago)
- Last Synced: 2024-04-14T18:49:57.405Z (about 2 years ago)
- Topics: formatter, json, json-library, marshalling, scala
- Language: Scala
- Homepage:
- Size: 93.8 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jello
[](https://travis-ci.org/romansky/jello)
[](https://www.scala-js.org)
[](http://search.maven.org/#artifactdetails|com.uniformlyrandom|jello_2.13|1.0.0|jar)
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
```scala
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
* `Enumeration`s support
* helper constructs to serialize `trait`s