RESTful Grails: how to include related objects in your XML?

Let's say I have a class called Store that has a lot of employees. The RESTful listXML method is as follows:

def listXML = {
    render Store.list() as XML
}

And the result will look like this:

<stores>
  <store id="1">
   <name>My Store</name>
   <employees>
     <employee id="1" />
   </employees>
  </store>
</store>

My question is: how do I include all the data of each Employee class so that my XML looks something like this?

   <stores>
      <store id="1">
       <name>My Store</name>
       <employees>
         <employee id="1">
           <name>John Smith</name>
           <hireDate>2008-01-01</hireDate>
         </employee>
       </employees>
      </store>
    </store>
+3
source share
2 answers

In your controller, you will want to import a deep converter:

import grails.converters.deep.XML

You can read about this in the first paragraphs of Link to Converters .

+5
source

Grails 1.1, Grails , grails-app/conf/Config.groovy:

grails.converters.xml.default.deep = true

1.1 . , "deep".

XML.use("deep") {
   render model as XML
}
+4

All Articles