io.github.scalapb-json:scalapb-playjson-macros_2.11

Json/Protobuf convertors for ScalaPB


Keywords
json, play-json, playframework, protobuf, scala, scala-js, scalapb
License
MIT

Documentation

scalapb-playjson

scaladoc

The structure of this project is hugely inspired by scalapb-json4s

Dependency

Include in your build.sbt file

core

libraryDependencies += "io.github.scalapb-json" %% "scalapb-playjson" % "0.17.0"

for scala-js or scala-native

libraryDependencies += "io.github.scalapb-json" %%% "scalapb-playjson" % "0.17.0"

macros

libraryDependencies += "io.github.scalapb-json" %% "scalapb-playjson-macros" % "0.17.0"

Usage

There are four functions you can use directly to serialize/deserialize your messages:

JsonFormat.toJsonString(msg) // returns String
JsonFormat.toJson(msg) // returns JsObject

JsonFormat.fromJsonString(str) // return MessageType
JsonFormat.fromJson(json) // return MessageType

Or you can use Reads/Writes/Format implicitly:

implicit val myMsgWrites: Writes[MyMsg] = JsonFormat.protoToWriter[MyMsg]

implicit val myMsgReads: Reads[MyMsg] = JsonFormat.protoToReads[MyMsg]

implicit val myMsgFormat: Format[MyMsg] = JsonFormat.protoToFormat[MyMsg]

Credits

fork from https://github.com/whisklabs/scalapb-playjson