akka-http-jawn-argonaut

Argonaut Support with Jawn parser for Akka HTTP

License

License

Categories

Categories

Akka Container Microservices Reactive libraries
GroupId

GroupId

de.knutwalker
ArtifactId

ArtifactId

akka-http-jawn-argonaut_2.10
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

akka-http-jawn-argonaut
Argonaut Support with Jawn parser for Akka HTTP
Project URL

Project URL

https://github.com/knutwalker/akka-http-jawn-argonaut/
Project Organization

Project Organization

de.knutwalker
Source Code Management

Source Code Management

https://github.com/knutwalker/akka-http-jawn-argonaut/

Download akka-http-jawn-argonaut_2.10

How to add to project

<!-- https://jarcasting.com/artifacts/de.knutwalker/akka-http-jawn-argonaut_2.10/ -->
<dependency>
    <groupId>de.knutwalker</groupId>
    <artifactId>akka-http-jawn-argonaut_2.10</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.knutwalker/akka-http-jawn-argonaut_2.10/
implementation 'de.knutwalker:akka-http-jawn-argonaut_2.10:1.0.0'
// https://jarcasting.com/artifacts/de.knutwalker/akka-http-jawn-argonaut_2.10/
implementation ("de.knutwalker:akka-http-jawn-argonaut_2.10:1.0.0")
'de.knutwalker:akka-http-jawn-argonaut_2.10:jar:1.0.0'
<dependency org="de.knutwalker" name="akka-http-jawn-argonaut_2.10" rev="1.0.0">
  <artifact name="akka-http-jawn-argonaut_2.10" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.knutwalker', module='akka-http-jawn-argonaut_2.10', version='1.0.0')
)
libraryDependencies += "de.knutwalker" % "akka-http-jawn-argonaut_2.10" % "1.0.0"
[de.knutwalker/akka-http-jawn-argonaut_2.10 "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.5
org.spire-math : jawn-argonaut_2.10 jar 0.8.3

provided (1)

Group / Artifact Type Version
com.typesafe.akka : akka-http-experimental_2.10 jar 1.0

test (1)

Group / Artifact Type Version
org.specs2 : specs2-core_2.10 jar 3.6.4

Project Modules

There are no modules declared in this project.

Build Status Coverage Maven Join at Gitter Apache License

Akka Streams Json Support

This library provides Json support for stream based applications using jawn as a parser. It supports all backends that jawn supports with support for circe provided as a example.

Installation

There are two main modules, akka-stream-json and akka-http-json. akka-stream-json is the basis and provides the stream-based parser while akka-http-json enabled support to use the desired json library as an Unmarshaller.

libraryDependencies ++= List(
  "de.knutwalker" %% "akka-stream-json" % "3.3.0",
  "de.knutwalker" %% "akka-http-json" % "3.3.0"
)

akka-stream-json depends on jawn-parser at version 0.10.4 and is compiled against akka-stream at version 2.4.17. The circe submodule depends on version 0.8.0 of circe-jawn The Akk Http submodule depends on version 10.0.7 of akka-http

akka-stream-json is published for Scala 2.12 and 2.11.

Usage

The parser lives at de.knutwalker.akka.stream.JsonStreamParser

Use one of the constructor methods in the companion object to create the parser at various levels of abstraction, either a Stage, a Flow, or a Sink. You just add the jawn support facade of your choice and you will can parsed into their respective Json AST.

For Http support, either import de.knutwalker.akka.http.JsonSupport._ or mixin ... with de.knutwalker.akka.http.JsonSupport.

Given an implicit jawn facade, this enable you to decode into the respective Json AST using the Akka HTTP marshalling framework. As jawn is only about parsing and does not abstract over rendering, you'll only get an Unmarshaller.

Circe

libraryDependencies ++= List(
  "de.knutwalker" %% "akka-stream-circe" % "3.4.0",
  "de.knutwalker" %% "akka-http-circe" % "3.4.0"
)

(Using circe 0.8.0)

Adding support for a specific framework is quite easy.

These support modules allow you to directly marshall from/unmarshall into your data types using circes Decoder and Encoder type classes.

Just mixin or import de.knutwalker.akka.http.support.CirceHttpSupport for Http or pipe your Source[ByteString, _].via(de.knutwalker.akka.stream.CirceStreamSupport.decode[A]) to get a Source[A, _].

This flow even supports parsing multiple json documents in whatever fragmentation they may arrive, which is great for consuming stream/sse based APIs.

If there is an error in parsing the Json you can catch de.knutwalker.akka.http.support.CirceStreamSupport.JsonParsingException. The exception provides Circe cursor history, current cursor and the type hint of the error.

Why jawn?

Jawn provides a nice interface for asynchronous parsing. Most other Json marshalling provider will consume the complete entity at first, convert it to a string and then start to parse. With jawn, the json is incrementally parsed with each arriving data chunk, using directly the underlying ByteBuffers without conversion.

License

This code is open source software licensed under the Apache 2.0 License.

Versions

Version
1.0.0