我在我的应用程序中使用了一个名为 PublishedState 的枚举。在我开始重构以支持 i18n 之前,我可以正常保存它。
以下是 Theme 域类的相关部分:
class Theme {
Map<String, String> name //language locale to name
Map<String,PublishedState> state //country locale to state
...
}
现在以下代码不起作用:
Theme theme = new Theme(
name: [en: 'english name'],
state: [en: PublishedState.DRAFT]
)
assert theme.validate()
theme.save()
我收到以下错误:
java.lang.IllegalArgumentException: can't serialize class com.example.myapp.PublishedState
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:234)
at org.bson.BasicBSONEncoder.putMap(BasicBSONEncoder.java:274)
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:196)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:140)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86)
at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
at com.mongodb.OutMessage.putObject(OutMessage.java:142)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:252)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:211)
at com.mongodb.DBCollection.insert(DBCollection.java:57)
at org.grails.datastore.mapping.mongo.MongoSession$1.doInDB(MongoSession.java:153)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:352)
at org.grails.datastore.mapping.mongo.MongoSession.flushPendingInserts(MongoSession.java:129)
at org.grails.datastore.mapping.core.AbstractSession.flush(AbstractSession.java:238)
at org.grails.datastore.mapping.mongo.MongoSession.flush(MongoSession.java:113)
at org.grails.datastore.gorm.support.DatastorePersistenceContextInterceptor.flush(DatastorePersistenceContextInterceptor.java:90)
at Console$_run_closure3_closure6_closure8.doCall(Console.groovy:74)
at Console$_run_closure3_closure6.doCall(Console.groovy:73)
at Console$_run_closure3_closure6.doCall(Console.groovy)
我找不到任何关于它的信息,只有关于保存列表和枚举集合的旧错误,这些应该已经解决了
我正在使用 Grails 版本:2.2.0,和 mongo 插件:mongodb:1.0.0.GA
有任何想法吗?
太感谢了!!!