Java 列表的节俭型建模<;HashMap<;字符串,对象>&燃气轮机;

Java 列表的节俭型建模<;HashMap<;字符串,对象>&燃气轮机;,java,thrift,Java,Thrift,我有一个Java服务方法,返回类型如下: List<HashMap<String,Object>> 列表 我怎样才能在节俭中对其进行最佳建模?非常简单: struct MyObjectData { // data of your objects } list< map< string, MyObjectData>> 如果您需要派生结构,我已通过以下操作为您解决了此问题: struct Base { // some fiel

我有一个Java服务方法,返回类型如下:

List<HashMap<String,Object>>
列表

我怎样才能在节俭中对其进行最佳建模?

非常简单:

struct MyObjectData {
    // data of your objects
}

list< map< string, MyObjectData>>
如果您需要派生结构,我已通过以下操作为您解决了此问题:

struct Base { 
    // some fields
}

struct Derived { 
    1: Base base_
    // some more fields
}

这对我来说很有效。如果您有一个很深的继承树,使用它可能会有点痛苦,但在我的特殊情况下并非如此。

AFAIK thrift不直接支持通用对象类型,它可以对您喜欢的任何对象进行类型转换。您必须像上面的示例中那样明确定义对象。不能将返回类型作为对象。 这里提到了一项工作:

struct Foo { /* some fields */ }
struct Bar { /* some fields */ }

// a union allows us to store different kinds of structs in one list
union Generic {
  1: Foo foo
  2: Bar bar
}

// technically, a union is more or less a struct with optional fields, 
struct Alternative {
  1: optional Foo foo
  2: optional Bar bar
}
struct Base { 
    // some fields
}

struct Derived { 
    1: Base base_
    // some more fields
}