xmlgrailsgroovygrails-2.4

Grail Deep XML Conversion


I have recently upgraded a Grails project to use version 2.4.4 from 1.3.7. After this upgrade I have an issue with XML conversion of the objects.

In my code I have used converter as:

import grails.converters.XML

def converter = policy as XML
String xml = converter.toString()

My Policy.groovy has below fields:

String policyNumber
String policyOrigin

static hasMany = [sources:Source, regions:Region]

In Grails 1.3.7, the converted XML had tags for the direct fields from Policy.groovy and the fields from Source and Region objects, but after upgrading Grails to 2.4.4, I see that the converted XML has tags only for the direct fields under Policy.groovy and just the top level tag for Source and Region objects, but no tags for the fields from these objects.

I have even tried with import grails.converters.deep.XML, but that didn't help.

Does anyone know how can I get the attributes from Source and Region objects to converted XML? Appreciate any pointers on this issue.


Solution

  • Setting the below property in grails-app\conf\Config.groovy resolved it for me.

    grails.converters.xml.default.deep = true
    

    Just to add a bit of further information, the pretty-print can be turned off by setting:

    grails.converters.xml.pretty.print = false