Skip to content

Json/Protobuf convertors for ScalaPB use play-json

License

Notifications You must be signed in to change notification settings

scalapb-json/scalapb-playjson

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

fd3b91c · Jan 13, 2025
Jun 27, 2024
Dec 25, 2023
Aug 26, 2024
Jan 9, 2025
Dec 18, 2019
Sep 29, 2016
Jun 26, 2023
Jan 13, 2025
Dec 31, 2017
Jun 27, 2024
Jan 11, 2025
Jun 27, 2024

Repository files navigation

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.18.0"

for scala-js or scala-native

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

macros

libraryDependencies += "io.github.scalapb-json" %% "scalapb-playjson-macros" % "0.18.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