1
對不起,這是一個Grails和Mongo的新手問題,因爲我讓自己感到困惑。POGO到Mongo DBObject
我有一個POGO(非域類)嵌套結構,我需要存儲在MongoDB中。我的示例代碼如下,但這隻會產生地圖頂層對象的屬性,並插入失敗,因爲嵌套的名稱對象
class Name {
String firstName
String lastName
}
class Details {
Name name
String street
String city
String postcode
Name[] siblings
}
// Get only the properties we want to save
def dbObject = details.properties.findAll { !['class', 'metaClass'].contains(it.key) }
// Insert it into the details collection
db.details.insert(dbObject)
我已經然後嘗試這個示例代碼答案Grails JSONBuilder但我得到下面的堆棧跟蹤
org.apache.commons.lang.UnhandledException: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Unconvertable Object of class: java.util.LinkedHashMap
at org.codehaus.groovy.grails.web.converters.AbstractConverter.toString(AbstractConverter.java:112)
at grails.converters.JSON.toString(JSON.java:232)
at grails.converters.JSON$toString.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at JSONSerializer.getJSON(JsonSerializer.groovy:21)
感謝您的建議 – Alex
好主意吉偉。有任何想法如何調用grails monodb插件的默認編組器? –