How can I read JSON data from C++ through Java using a piqi definition

606 Views Asked by At

We use a 3rd party REST web service which defines their json API using piqi schemas. Our current architecture needs this data to be read through a java client and transferred to a c++ binary. Ideally, I would like all of the POJOs and c++ structs, as well as the data translation (json->java, java->c++) logic to be generated. I've been investigating different combinations of protobuf, protostuff, and thrift, but there are still gaps in the flow. Anyone have suggestions?

1

There are 1 best solutions below

0
On

Piqi author here. Most likely the third-party API provider exposes the JSON over HTTP API using piqi-rpc. Assuming you have the up-to-date .piqi definitions of the service there's a chance you can get output and/or send input data in Protocol Buffers format instead of JSON. Dealing with Protobuf in both Java and C++ is a lot easier and more reliable than dealing with JSON.

Unless the API provider explicitly disables use of Protocol Buffers as input/output format, you should be able to use this format by setting Accept header (and Content-Type for input parameters) to application/x-protobuf as described here. I would just try that and see if it works. If it doesn't you can ask the provider to turn it on.