如何在 mongodb 的 spring-data 中映射枚举集合
spring-data 1.0.0.M3 与 MongoDB。为什么 spring 可以映射这个类:
import org.springframework.data.document.mongodb.index.IndexDirection;
import org.springframework.data.document.mongodb.mapping.Document;
@Document
public class EnumsMapper {
private IndexDirection d = IndexDirection.ASCENDING;
}
却失败了:
import org.springframework.data.document.mongodb.index.IndexDirection;
import org.springframework.data.document.mongodb.mapping.Document;
import java.util.List;
import java.util.Arrays;
@Document
public class EnumsMapper {
List<IndexDirection> list_enum_test = Arrays.asList(
new IndexDirection[] {IndexDirection.ASCENDING});
}
与 a:
java.lang.IllegalArgumentException: can't serialize class org.springframework.data.document.mongodb.index.IndexDirection
其他集合(集合,...)和数组也会发生同样的情况。显然spring可以映射这个枚举,所以编写映射器并不能解决问题。这是一个错误还是有办法映射包含枚举的集合(集合/映射)?
spring-data 1.0.0.M3 with MongoDB. How come spring can map this class:
import org.springframework.data.document.mongodb.index.IndexDirection;
import org.springframework.data.document.mongodb.mapping.Document;
@Document
public class EnumsMapper {
private IndexDirection d = IndexDirection.ASCENDING;
}
and fails with this one:
import org.springframework.data.document.mongodb.index.IndexDirection;
import org.springframework.data.document.mongodb.mapping.Document;
import java.util.List;
import java.util.Arrays;
@Document
public class EnumsMapper {
List<IndexDirection> list_enum_test = Arrays.asList(
new IndexDirection[] {IndexDirection.ASCENDING});
}
with a:
java.lang.IllegalArgumentException: can't serialize class org.springframework.data.document.mongodb.index.IndexDirection
The same happens with other collections (sets, ...), and also arrays. Obviously spring can map this enum, so writing a mapper doesn't solve the problem. Is this a bug or there's a way to map a collection (set/map) holding enums?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来你发现了一个错误:)。这是错误,这是修复。快照二进制文件部署到我们的 Maven 存储库。请随意尝试一下,并在票证中添加评论,以防您仍然遗漏某些内容。
It seems you discovered a bug :). Here's the bug, here's the fix. Snapshot binaries deployed to our Maven repo. Feel free to give it a try and add comments to the ticket in case you're still missing something.