Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4285

XmlUtil.serialize doesn't seem to pick right method for GPathResult

    Details

      Description

      The following gives an error:

      import groovy.xml.XmlUtil
      import groovy.xml.StreamingMarkupBuilder
      
      def xmlStr = """<?xml version="1.0" encoding="UTF-8"?>
      <stuff ver="1.0">
        <properties>
          <foo>bar</foo>
        </properties>
      </stuff>"""
      
      def gpr = new XmlSlurper().parseText( xmlStr )
      println XmlUtil.serialize( gpr )
      

      Gives the following error:

      [Fatal Error] :1:1: Content is not allowed in prolog.
      ERROR:  'Content is not allowed in prolog.'
      <?xml version="1.0" encoding="UTF-8"?>
      

      However if we change the println to:

      println XmlUtil.serialize( (groovy.util.slurpersupport.GPathResult)gpr )
      

      We get the correct output:

      <?xml version="1.0" encoding="UTF-8"?>
      <stuff ver="1.0">
        <properties>
          <foo>bar</foo>
        </properties>
      </stuff>
      

      Looks like Groovy is picking the wrong method somewhere... (though I can't see how)

        Attachments

          Activity

            People

            • Assignee:
              roshandawrani Roshan Dawrani
              Reporter:
              tim_yates Tim Yates
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: