[
https://issues.apache.org/jira/browse/GROOVY-11801?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
James Daugherty closed GROOVY-11801.
------------------------------------
Resolution: Invalid
> Markup Builder no longer executes methods inside of closure
> -----------------------------------------------------------
>
> Key: GROOVY-11801
> URL: https://issues.apache.org/jira/browse/GROOVY-11801
> Project: Groovy
> Issue Type: Bug
> Components: XML Processing
> Affects Versions: 4.0.0, 4.0.29
> Reporter: James Daugherty
> Priority: Major
>
> Given this groovyConsole script:
> {code:java}
> import groovy.xml.MarkupBuilder
> class XmlGenerator {
> private MarkupBuilder builder = null
>
> String write() {
> Map someData = [
> details: [
> [
> myId: 200,
> breakdowns: [
> unit: 'test1'
> ]
> ]
> ]
> ]
>
> xmlToString(getWriter(someData))
> }
>
> String xmlToString(@DelegatesTo(MarkupBuilder) Closure c) {
> def writer = new StringWriter()
> def xml = new MarkupBuilder(writer)
> xml.doubleQuotes = true
> xml.escapeAttributes = true
> xml.mkp.xmlDeclaration(version: "1.0", encoding: "UTF-8")
> builder = xml
> c.delegate = xml
> c.resolveStrategy = Closure.DELEGATE_FIRST
> c.call(xml) builder = null writer.toString()
> }
>
> Closure getWriter(Map someData) {
> Closure c = { MarkupBuilder xml ->
> Map parentArgs = [a: '1', b: '2']
> parent(parentArgs) {
> comments {
> mkp.yield "testing a comment"
> }
>
> for(def someDetails : someData.details) {
> details(getDetailArgs(someDetails)) {
>
> }
> }
> }
> }
> }
>
> Map getDetailArgs(Map someDetails) {
> [id: someDetails.myId]
> }
> }
> new XmlGenerator().write() {code}
> In Groovy 3.x this generated the following xml:
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <parent a="1" b="2">
> <comments>testing a comment</comments>
> <details id="200" />
> </parent> {code}
> In Groovy 4.x, the method `getDetailArgs` is not being executed so it
> generates this instead:
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <parent a="1" b="2">
> <comments>testing a comment</comments>
> <getDetailArgs myId="200" breakdowns="{unit=test1}" />
> <details>getDetailArgs</details>
> </parent> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)