我需要在grails中使用com.fasterxml.jackson.databind.ObjectMapper的共享實例,所以我認爲最標準的方法是通過beans DSL。 我想是這樣(有許多變化,比如使用delegate關鍵字)在resources.groovy通過Grail的bean配置Jackson的ObjectMapper DSL
objectMapper(ObjectMapper) { bean ->
bean.setVisibility(PropertyAccessor.ALL, Visibility.ANY)
bean.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}
,但它沒有工作,ObjectMapper配置的默認方式,不使用Grails很好地工作。 我用一種變通方法,其做什麼,我需要(BootStrap.groovy中):
def init = { servletContext ->
def bean = Holders.applicationContext.objectMapper
bean.setVisibility(PropertyAccessor.ALL, Visibility.ANY)
bean.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}
任何人都可以點我怎麼做,在豆類DSL,它屬於(恕我直言)?
謝謝,子類似乎對我很好,很簡單(它的工作原理)。 如果沒有人使用純粹的DSL解決方案,我會接受這個 –