我将 Ektorp 框架用作 CouchDB 的 Java“ORM”。它使用 Jackson 对 JSON 文档进行(反)序列化。
我有以下层次结构:
public class Animal extends CouchDbDocument {
private int numberOfLegs;
// Getters and setters ...
}
public class Dog extends Animal {
private String name;
// Getters and setters
}
我已将 3Animal
秒和 1保存Dog
到我的 CouchDB 中。
执行时List<Dog> dogs = dogRepository.getAll()
,我得到一个包含 4 个对象的集合(其中 3 个name
是NULL
)。这是因为 Jackson/Ektorp 似乎默认不处理继承。
那么如何处理继承呢?我希望不会得到 4 个对象,而只会得到 1 个(Dog
)。
更新 我只是试图删除继承。问题仍然存在。因此,Ektorp/Jackson 似乎无法检测到类类型。