ScalaPB and JSON
ScalaPB can convert protocol buffers to and from JSON, using json4s.
Setting up your project
Make sure that you are using ScalaPB 0.5.x or later.
build.sbt add a dependency on
In your code, you can now convert to JSON:
Parse JSON back to a protocol buffer:
There are lower-level functions
fromJson() that convert from
protos to json4s’s
Finally, in JsonFormat there are two implicit methods that instantiate
More printing and parsing options
There are a few more options available to customize the format used to print
and parse JSON. To take advantage of that, instantiate
fromJson() as usual.
See the list of constructor paramerters here