2011-07-21 21 views
2

spring-data 1.0.0.M3 with MongoDB。为什么春天可以在这个类映射:如何在春天数据中为MongoDB映射一组枚举集合

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}); 

} 

有:

java.lang.IllegalArgumentException: can't serialize class org.springframework.data.document.mongodb.index.IndexDirection 

同样的情况,与其他收藏品(套,... )和数组。很显然,spring可以映射这个枚举,所以编写一个映射器并不能解决问题。这是一个错误还是有办法映射一个集合(set/map)来保存枚举?

回答

2

看来你发现了一个bug :)。这里的the bug,这里是the fix。快照二进制文件部署到我们的Maven回购。随时尝试一下,并在票上添加评论以防万一你仍然遗漏了一些东西。

+1

链接被破坏... – slim