The main issue probably is that TSimpleJSONProtocol erases information
that is critical to reading uses Thrift's standard semantics; for
example TSimpleJSONProtocol encodes fields using field names, but when a
protocol is reading a field it expects a field identifier to be
returned. There are other impedance mismatches as well - such as
protocols reading maps/lists/sets expect for type information and size
to be encoded at the start of the collection, otherwise you need to read
ahead to determine this information dynamically, which could get
complicated especially for nested structures.
I ran into these problems a little while back when trying to convert
between Thrift and XML, and the solution that I've found is to use a
metadata file to add back in the needed information. I have this working
for XML, and doing it with JSON would not be conceptually different.
You can find my code here (the documentation has not been updated in the
last few weeks though):
https://github.com/bgould/thriftee/tree/master/thriftee-xml-protocol
The build is sort of specific to my environment right now but you can at
least browse the code... the XSLT that does the heavy lifting is in
src/main/resources. If you're dealing with JSON you could replace XSLT
with transformations coded in whatever language you like, and ascertain
the metadata you need by using the output of Thrift's JSON generator.
It might also be possible in Java to get the metadata via reflection on
the generated structs, since they have a member variable called _Fields
that contains that information.
Good luck! ;)
https://github.com/bgould/thriftee/tree/master/thriftee-xml-protocol
On 01/11/2016 11:40 PM, Joseph TechMails wrote:
Hi,
It's known that TSimpleJSONProtocol is write-only. Is there any reason why
a read/write version is not supported and is there an alternate approach to
achieve this? My project has been using TJSONProtocol, but now we need to
expose this data for Solr indexing which requires a more readable format.
Also, in the docs there's a mention of TDebugProtocol, but i couldn't find
it in the java library (libthrift-0.9.3.jar). Can someone share how it
looks like ?
Thanks,
Joseph