|
I have a controller where I'm simply rendering the retrieved objects as XML:
def show() { if (params.id) { def conf = Conformance.findById(params.id) if (conf == null) { render "No Conformance" } else { render conf as XML } } else { def all = Conformance.list() render all as XML } } When I run the unit test on this, I get a conversion error. After debugging, it appears that it's because the renderer doesn't like the MockObject proxy that is being passed to it: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class org.springframework.beans.GenericTypeAwarePropertyDescriptor at grails.converters.XML.render(XML.java:115) at grails.converters.XML.render(XML.java:252) at org.codehaus.groovy.grails.plugins.converters.api.ConvertersControllersApi.render(ConvertersControllersApi.groovy:40) at com.healthfire.ConformanceController.show(ConformanceController.groovy:17) at com.healthfire.ConformanceControllerSpec.convert all conformances to XML(ConformanceControllerSpec.groovy:24) Caused by: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Error converting Bean with class org.springframework.beans.GenericTypeAwarePropertyDescriptor at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:65) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:33) at grails.converters.XML.convertAnother(XML.java:169) at org.codehaus.groovy.grails.web.converters.marshaller.xml.ArrayMarshaller.marshalObject(ArrayMarshaller.java:41) at org.codehaus.groovy.grails.web.converters.marshaller.xml.ArrayMarshaller.marshalObject(ArrayMarshaller.java:29) at grails.converters.XML.convertAnother(XML.java:169) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:47) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:33) at grails.converters.XML.convertAnother(XML.java:169) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:47) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:33) at grails.converters.XML.convertAnother(XML.java:169) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GroovyBeanMarshaller.marshalObject(GroovyBeanMarshaller.java:48) at org.codehaus.groovy.grails.web.converters.marshaller.xml.GroovyBeanMarshaller.marshalObject(GroovyBeanMarshaller.java:34) at grails.converters.XML.convertAnother(XML.java:169) at org.codehaus.groovy.grails.web.converters.marshaller.xml.CollectionMarshaller.marshalObject(CollectionMarshaller.java:43) at org.codehaus.groovy.grails.web.converters.marshaller.xml.CollectionMarshaller.marshalObject(CollectionMarshaller.java:31) at grails.converters.XML.convertAnother(XML.java:169) at grails.converters.XML.render(XML.java:111) ... 4 more Caused by: java.lang.IllegalAccessException: Class org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller can not access a member of class org.springframework.beans.GenericTypeAwarePropertyDescriptor with modifiers "public" at org.codehaus.groovy.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller.marshalObject(GenericJavaBeanMarshaller.java:45) ... 22 more Here is my test in case I'm doing something quite silly (note that it's a Spock test): @TestFor(ConformanceController) @Mock(Conformance) class ConformanceControllerSpec extends grails.plugin.spock.ControllerSpec { def "convert all conformances to XML"() { setup: mockDomain(Conformance, [ new Conformance(date: new Date(), fhirVersion: "0.5", narrative: "test conformance 1"), new Conformance(date: new Date(), fhirVersion: "0.5", narrative: "test conformance 2"), new Conformance(date: new Date(), fhirVersion: "0.5", narrative: "test conformance 3") ]) when: controller.show() then: response.contentType == "text/xml" } Thanks, |
|
I similar issue with JSON. It is one of the most frustrating aspects of Grails. I'm about to finish a blog post about it. In short, this is what I did.
I created a JsonService that uses groovy's native JsonBuilder. This converts my objects to JSON. I call this service from my controller and pass it to the render method:
render(contentType : "application/json"{ jsonService.render(myDomainInstance) } Then my tests pass. I noticed that the issue only happens when testing. If you do run-app, then grails works fine when I do render domainInstance as JSON.
On Thu, Jul 26, 2012 at 2:55 AM, Jean-Henri Duteau <[hidden email]> wrote:
The Journey Is The Reward. |
| Powered by Nabble | Edit this page |
