I wanted to represent a standard tree structure in apache thrift, but I encountered following problem:
[ERROR:/path_to_project/thrift/service.thrift:31] (last token was 'TCategoryTree')
Type "TCategoryTree" has not been defined.
These are my thrift 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 I'm defining right now.
Could it be that apache thrift doesn't support recursive structures or am I making some kind of mistake here?
edit: I'm using version 0.9.0
Yes, unfortuantely Thrift does not allow recursive structures yet. There are workarounds for this limitation, e.g. flatten your data structures while transmitting them. In most cases this is feasible, although it requires some extra code on both sides.
Here's a good example how to do it: http://grokbase.com/t/thrift/user/0984cqwxen/recursive-datatypes
Update
The current Thrift development trunk supports this for a while now. Be careful, as it allows for endless reference loops (A references B references A ...) resulting in an stack overflow when trying to serialize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With