Java – common objects in Apache thrift

I wonder if I can use IDL language to define "general object" in Apache thrift, similar to the "object" class in Java

I need to send a list of objects of any type, but I don't know how to do it in file Define it in thrift

like this:

struct
{
   1: list<object> listObjects;
}

or

struct
{
   1: list<?> listObjects;
}

Solution

Apache thrift does not support structure inheritance or self - reference structures That's what you want to do. It's impossible to pass a polymorphic list directly There are ways to solve this problem, such as serializing objects into binaries, passing a list of binaries, and deserializing them at the other end

struct abc {
    1: list<binary> myList,}

All Apache thrift structures have read and write methods. You can use these methods to serialize them into memory buffer (tmemorybuffer), and then you can use them as binary objects of the list Another option might be to use a union

union myTypes {
    1: double dbl
    2: i64 bigInt
    3: SomeOtherStruct sos
}

struct abc {
    1: list<myTypes> myList,}

This method creates a list of mytypes union types, but the union can accommodate any IDL definition type you like

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>