ProductPromotion
Logo

Scala

made by https://0x3d.site

GitHub - scala-jsonapi/scala-jsonapi: Scala support library for integrating the JSON API spec with Spray, Play! or Circe
Scala support library for integrating the JSON API spec with Spray, Play! or Circe - scala-jsonapi/scala-jsonapi
Visit Site

GitHub - scala-jsonapi/scala-jsonapi: Scala support library for integrating the JSON API spec with Spray, Play! or Circe

GitHub - scala-jsonapi/scala-jsonapi: Scala support library for integrating the JSON API spec with Spray, Play! or Circe

Description

Build Status Coverage Status codecov.io Join the chat at https://gitter.im/zalando/scala-jsonapi Maven Central Javadocs

scala-jsonapi is a Scala library that aims to help you produce JSON output based on the JSON API specification easily and painlessly. The library is compatible with Scala version 2.11. It supports read and write for the following backends:

In addition, scala-jsonapi provides out-of-the-box (un)marshallers for:

  • Spray and Play
  • Akka Http

Current Status

This library is very much a work in progress, so expect its API to change.

Setup

To use scala-jsonapi, first add a library dependency—assuming that you have sonatype resolvers set up.

libraryDependencies += "org.zalando" %% "scala-jsonapi" % "0.6.2"

You also have to provide the used backend (e.g. spray-json).

Usage

The rich JSON API model is available via the following import:

import org.zalando.jsonapi.model._

The library provides serialization and deserialization of JSON API root objects to JSON using either Spray-JSON or Play-JSON. Please note that you need to explicitly add a dependency to either spray-json or play-json to your project.

Spray-JSON

import org.zalando.jsonapi.json.sprayjson.SprayJsonJsonapiProtocol._
import spray.json._

// Serialization
val rootObject: RootObject = ???
rootObject.toJson

// Deserialization
val json: JsValue = ???
json.convertTo[RootObject]

Play-JSON

Along with adding the scala-jsonapi library dependency, also include spray-httpx for marshalling support

libraryDependencies += "io.spray" %% "spray-httpx" % "1.3.3"

The JSON API support can then be imported using PlayJsonJsonapiSupport as follows

import org.zalando.jsonapi.json.playjson.PlayJsonJsonapiSupport._
import play.api.libs.json._

// Serialization
val rootObject: RootObject = ???
Json.toJson(rootObject)

// Deserialization
val json: JsValue = ???
Json.fromJson[RootObject](json)

Creating a JSON API Root Object

scala-jsonapi provides type class JsonapiRootObjectWriter so that you can create a JSON API representation for your resources. The following code snippet demonstrates its usage:

import org.zalando.jsonapi
import jsonapi.Jsonapi

case class Person(name: String)

implicit val personJsonapiWriter = new JsonapiRootObjectWriter[Person] {
  override def toJsonapi(person: Person) = {
    ???
  }
}

val personRootObject: RootObject = Jsonapi.asJsonapi(Person("Boris M."))

In contrast there is a type class called JsonapiRootObjectReader that supports conversion from JSON API representation to your resources. To illustrate:

import org.zalando.jsonapi
import jsonapi.Jsonapi

case class Person(name: String)

implicit val personJsonapiReader = new JsonapiRootObjectReader[Person] {
  override def fromJsonapi(rootObject: RootObject) = {
    ???
  }
}

val person: Person = Jsonapi.fromJsonapi[Person](RootObject(...))

For complete usage, see the specs example.

JSON API Links Support

There is support for string and object links.

To create a string "self" link:

Links.self("href", None)

To create an object "self" link:

Links.self("href", Some(meta))

Publishing and Releasing

Publishing and releasing is made with help of the sbt-sonatype plugin.

License

scala-jsonapi is licensed under the MIT license unless otherwise stated in the license files in higher directories (if any).

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory