I'm struggling with getting a groovy script to output what I need adhering to a vendor spec. Eventually, I will populate JsonSlurper with a file rather than static rows, but for simplicity I've provided sample JSON. When running the following code in GroovyConsole, I can't seem to pinpoint why the UserReference and Bal nodes are including the namespace I specify. Any help is appreciated!
import groovy.xml.*
import groovy.json.JsonSlurper
def queryResultsResponseString =
'''
{
"rows": [
{
"account_num": 123,
"name": "Mr Bigbucks",
"balance": 83.23
},
{
"account_num": 8675309,
"name": "Johnny",
"balance": 45.75
}
]
}
'''
def jsonResp = (new JsonSlurper()).parseText(queryResultsResponseString);
def xml = new groovy.xml.StreamingMarkupBuilder()
xml.encoding = "UTF-8"
def prints = xml.bind{
mkp.xmlDeclaration()
mkp.declareNamespace(p1 :"com/my/namespace/woot" + "\"" + " " + "xsi:schemaLocation=\"http://www.w3.org/2001/XMLSchema-instance")
'p1:BatchEidvPersonSearch' {
jsonResp.rows.each{row ->
EidvPersonSearchRequest {
InternalId('Internal Id')
UserReference('CLEAR ID Confirm Person Search')
criteria {
acctNum row.account_num
custName row.name
bal row.balance
}
}
}
}
}
println XmlUtil.serialize(prints).replaceAll('"','"')
// ---Results Here ---
<?xml version="1.0" encoding="UTF-8"?><p1:BatchEidvPersonSearch xmlns:p1="com/my/namespace/woot" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">
<EidvPersonSearchRequest>
<InternalId>Internal Id</InternalId>
<UserReference xmlns:p1="com/my/namespace/woot" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">CLEAR ID Confirm Person Search</UserReference>
<criteria>
<acctNum>123</acctNum>
<custName>Mr Bigbucks</custName>
<bal xmlns:p1="com/my/namespace/woot" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">83.23</bal>
</criteria>
</EidvPersonSearchRequest>
<EidvPersonSearchRequest>
<InternalId>Internal Id</InternalId>
<UserReference xmlns:p1="com/my/namespace/woot" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">CLEAR ID Confirm Person Search</UserReference>
<criteria>
<acctNum>8675309</acctNum>
<custName>Johnny</custName>
<bal xmlns:p1="com/my/namespace/woot" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">45.75</bal>
</criteria>
</EidvPersonSearchRequest>
</p1:BatchEidvPersonSearch>
--- Update -----
I am attempting to invoke this Groovy script through an ETL tool that comes with the 2.2 Groovy Jar loaded locally and noticed that when invoking the script through the ETL tool, it produces the output I expect. So...I downloaded 2.2 groovy from the archives and invoke my script using groovy console and BAM it works. I'm not sure what changed between versions, but there's definitely a change in output. I suspect that when we upgrade our ETL tool, the JAR will be refreshed with the later-est version. Any ideas what might be significantly different between the two releases?