简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM