Search code examples
javacommunicationthrift

How to use a struct defined in a Thrift file using keyword "include"


I'm a newbie with Thrift. I have the following question: Suppose that I defined a struct in file "Ex1.thrift" as follow:

namespace java tut1
struct Address {
 1:string nameStreet,
 2:i32 idHouse
}

I want to use struct Address in file "Ex2.thrift", how could I do that? I tried this way but Thrift compiler doesn't work:

include "Ex1.thrift"
namespace java tut2
struct Student {
 1:string name,
 2:i32 age,
 3:Address add
}

service ExampleService {
 list<Student> getListStudent()
}

Thank you so much for any answer.


Solution

  • You need to provide Ex1 prefix while using address in Ex2.thrift

        include "Ex1.thrift"
        namespace java tut2
        struct Student {
        1:string name,
        2:i32 age,
        3:Ex1.Address add
        }
    
        service ExampleService {
        list<Student> getListStudent()
        }
    

    This works in Thrift 0.8.0