Types and play-json Format instances for JSON-RPC 2.0 messages, with application command, response and notification marshalling support.
Note that up until version 1.5.0 scala-json-rpc was called play-json-rpc. It was originally developed for use in both the server and client side of Liquidity.
resolvers += Resolver.bintrayRepo("dhpcs", "maven")
libraryDependencies += "com.dhpcs" %% "scala-json-rpc" % "x.y.z"
The CommandCompanion
, ResponseCompanion
and NotificationCompanion
bases
defined in
MessageCompanions.scala
provide readers and writers for hierarchies of application level types. Example
use can be seen in
MessageCompanionsSpec.scala.
The JSON-RPC message types are represented by an ADT defined in JsonRpcMessage.scala. The JsonRpcMessage JsonRpcMessageSpec.scala shows how they appear when marshalled to and from JSON.
Note that typical usage does not involve the direct construction of the low level JSON-RPC message types. The recommended approach is to make use of the writers provided by the companion bases as demonstrated in the previously linked marshalling specification.
The companion object for the JsonRpcMessage
trait provides a play-json Format
typeclass instance that can read and write "raw" JsonRpcMessage
types. If you
are reading messages received over e.g. a websocket connection and thus don't
know what message type to expect at a given poiint, you can simply match on the
subtype of the result and then use the appropriate application specific
companion to unmarshall the content to one of your application protocol's
types. Similarly, when marshalling your application protocol's types, you'll
first pass them to the appropriate application specific companion and then
format the result of that as JSON, implicitly making use of the relevant
provided typeclass instance.
scala-json-rpc is licensed under the Apache 2 License.