Reputation: 1
I'm quite new to Groovy and couldn't find the right way to format/edit data in groovy when defining xml. I'd like to format my date to some custom format but I can't call any method from inside this closure, so the following fails :
def response = {
mkp.pi(xml:"version='1.0' encoding ='UTF-8'")
response () {
status(0)
count(data.size)
objects() {
data.each { row ->
object() {
someId(row.myId)
objectDate(callSomeMethodtoFormatTheDate(row.someDate))
}
}
}
}
Thanks
Upvotes: 0
Views: 148
Reputation: 721
Try this:
Call the method outside of the closure and return the data to a variable. Then use the variable to reference the data in the closure.
Example:
var = callSomeMethodtoFormatTheDate(row.someDate)
def response = {
mkp.pi(xml:"version='1.0' encoding ='UTF-8'")
response () {
status(0)
count(data.size)
objects() {
data.each { row ->
object() {
someId(row.myId)
objectDate(var)
}
}
}
}
Upvotes: 0