You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2026/10/20 01:27:01 UTC

[jira] [Closed] (GROOVY-11927) Add toMap() and typed parsing support to XmlParser

     [ https://issues.apache.org/jira/browse/GROOVY-11927?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-11927.
------------------------------

> Add toMap() and typed parsing support to XmlParser
> --------------------------------------------------
>
>                 Key: GROOVY-11927
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11927
>             Project: Groovy
>          Issue Type: Improvement
>          Components: XML Processing
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 6.0.0-alpha-1
>
>
> Add {{Node.toMap()}} for converting XML node trees to nested Maps, and {{XmlParser.parseTextAs()}} / {{parseAs()}} for typed XML parsing via Jackson databinding.
> Three levels of support:
> * `node.toMap()` — zero-dependency conversion to `Map<String, Object>`, usable standalone
> * `node as MyType` — coercion via `toMap()` + Groovy's named-param constructor (works for String-typed properties, no additional deps)
> * `parser.parseTextAs(Type, xml)` — full typed conversion (String→int, boolean, etc.) plus `@JsonProperty`/`@JsonFormat` support; requires `jackson-databind` at runtime, throws clear error if absent
> Also adds {{XmlRuntimeException}} and an internal {{JacksonHelper}} utility using reflective access to avoid a compile-time Jackson dependency on {{groovy-xml}}.
> {code:groovy}
> static class ServerConfig {
>     String host
>     int port
>     boolean debug
> }
> def config = new XmlParser().parseTextAs(ServerConfig, '''
>     <server>
>         <host>localhost</host>
>         <port>8080</port>
>         <debug>true</debug>
>     </server>'''.stripIndent())
> assert config instanceof ServerConfig
> assert config.host == 'localhost'
> assert config.port == 8080
> assert config.debug == true
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)