Apache thrift does not create recursive structures

I wanted to introduce a standard tree structure in Apache, but I encountered the following problem:

[ERROR:/path_to_project/thrift/service.thrift:31] (last token was 'TCategoryTree') Type "TCategoryTree" has not been defined. 

These are my lean structures:

 struct TCategory { 1: required string name } struct TCategoryTree { 1: required TCategory element, 2: optional list<TCategoryTree> children } 

Line 31 is 2: optional list<TCategoryTree> children , where I define a field that has the same type that I am defining right now.

Could it be that apache thrift does not support recursive structures or am I making some kind of mistake here?

edit: I am using version 0.9.0

+6
source share
1 answer

Yes, unfortunately, Thrift does not yet allow recursive structures. Possible workarounds for this limitation, for example. smooth your data structures as you transfer them. In most cases, this is possible, although this requires additional code on both sides.

Here is a good example of how to do this: http://grokbase.com/t/thrift/user/0984cqwxen/recursive-datatypes


Update

The current Thrift development branch has been supporting this for a while. Be careful, as this allows endless looping of links (A refers to B-links A ...), which leads to a stack overflow when trying to serialize.

+7
source

All Articles