【问题标题】:how to map a collection of enums in spring-data for mongodb如何在spring-data中为mongodb映射枚举集合
【发布时间】:2011-10-10 10:20:46
【问题描述】:

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

}

带有:

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

同样的情况也发生在其他集合(集合、...)以及数组中。显然spring可以映射这个枚举,所以写一个mapper并不能解决问题。这是一个错误还是有办法映射一个包含枚举的集合(集合/映射)?

【问题讨论】:

    标签: mongodb spring-data


    【解决方案1】:

    您似乎发现了一个错误:)。这里是the bug,这里是the fix。快照二进制文件部署到我们的 Maven 存储库。随意尝试一下,并将 cmets 添加到票证中,以防您仍然缺少某些东西。

    【讨论】:

    • 两个链接都没有找到。
    猜你喜欢
    • 2016-12-29
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 2019-06-05
    相关资源
    最近更新 更多