【发布时间】:2017-03-02 00:06:49
【问题描述】:
我想使用组合模式来重用类的公共部分,就像我在 Jackson 中使用 @JsonUnwrapped 所做的那样,而不在 mongodb 文档中添加额外级别的结构,例如:
class A {
int x; int y;
}
class B {
@JsonUnwrapped
A a;
}
class C {
@JsonUnwrapped
A a;
}
所以当 B 或 C 存储在 mongodb 中时,它看起来像:
{ x:123, y:456 }
而不是
{ a: { _class:"A", x:123, y:456 } }
很遗憾,我在spring-data-mongodb annotations 或core spring data annotations 中找不到合适的注释。一个存在吗?我知道这必然使 A 子结构的多态性成为不可能。
【问题讨论】:
标签: mongodb spring-data-mongodb