views:

30

answers:

0

Expecting grails domain object to be written to XML response:

Image.groovy:


@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
class Image{

         @XmlElement
 String url
 @XmlElement
 String contentType
}

WebServiceRequestHandler.groovy:


@GET
 @Path("/myrestfullmethod/parameter1/{parameter1name}
 @Produces("text/xml")
 ImagesWrapper getImageMetadata(@PathParam('parameter1name') String pParameter1)
 {
  def images = methodThatReturnsImagePointingToHibernatePersistantObject(pParameter1)

  return images
 }

cxf is configured with:

<jaxrs:server id="cxfJaxRsServer" address="/">
  <jaxrs:serviceBeans>
    <ref bean="webServiceRequestHandler" />
  </jaxrs:serviceBeans>
  <jaxrs:providers>
   <ref bean="codeGenerator" />
   <ref bean="jaxbProvider" />   
  </jaxrs:providers> 
 </jaxrs:server>


 <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" scope="singleton">
  <property name="marshallerProperties">
   <map>
    <entry key="jaxb.formatted.output">
     <value type="java.lang.Boolean">true</value>
    </entry>
   </map>
  </property>
 </bean>

however what comes back is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<images>
    <image></image>
</images>

I have a workaround which is to add:

static mapping = {
  image lazy: false
 }
in class that has set of images (and a reverse entry on the image referencing the class it belongs to).

However lazy-loading works just fine for writing JSON data out.

suggestions for what I'm missing would be appreciated - does JAXB, when reading the annotations to marshal the hibernate persistent object to xml, call the annotated attributes not trigger hibernate to call for the real value? How do I trigger this?

Suggestions appreciated. Hope its something obvious I've not configured, or just a suggestion for how to debug.

Thanks

Alex