According to the documentation scalapb is able to parse arbitrary protobuf messages into json format. However, I cannot make heads or tails of their documentation and my code simply does not compile:
// apparently the Companion Object provides the parser
// and com.google.protofbuf.Any is a catch-all for protobuf messages of unknown content
val proto : protobuf.Any = com.google.protobuf.Any.parseFrom(request.contentRaw)
// according to the documentation you can convert a given parsed protobuf to json using this printer
val json = new scalapb.json4s.Printer(preservingProtoFieldNames = true)
// now I want to print the parsed message
printer.print(proto)
but now the compiler tells me that I have parsed the wrong type?
[error] found : com.google.protobuf.Any
[error] required: scalapb.GeneratedMessage
[error] printer.print(proto)
How can I parse and print as json an arbitrary and unknown protobuf using scalapb?
It seemed faster to write it myself, as I could not figure it out. If there is a canonical solution, I am more than happy to accept the corresponding answer. But for now: