我将MongoDB专门用于Grails REST应用程序和以下所示的域。此响应 call 失败:
@Secured(['permitAll'])
def index() {
respond Person.list()
}
与错误
ERROR errors.GrailsExceptionResolver - IllegalAccessException occurred when processing request: [GET] /teesheet/person
Class org.codehaus.groovy.grails.web.converters.marshaller.json.GroovyBeanMarshaller can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public". Stacktrace follows:
Message: Class org.codehaus.groovy.grails.web.converters.marshaller.json.GroovyBeanMarshaller can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
尝试将集合转换为JSON也会失败,并显示相同的错误。
def personList = Person.list() as JSON
low level API有效。
package com.tworks.teesheet
import grails.rest.Resource
class Person {
String name
String firstName
String lastName
String email
User userPerson
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles")
Date dateCreated = new Date()
Date dateModified = new Date()
}
最佳答案
假设您使用的是Mongo for Grails插件,则域类需要@Entity
...
import grails.persistence.Entity
@Entity
class Person {
static mapWith = "mongo"
String name
String firstName
String lastName
String email
}
我添加了
mapWith="mongo"
,因为我不确定您是否在mongo插件旁边使用了hibernate插件;如果不是,请删除休眠模式,否则,它可能为interfere。
关于grails - MongoDB集合访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587435/