I have the following code that works with Groovy 2.5.7:
import groovy.json.JsonBuilder
def name = "foo"
def builder = new JsonBuilder()
builder {
_id name
contactInformation {
telephoneNumber("12345")
emailAddress("foo@foo.com")
}
}
println builder.toString()
Same code with groovy 3.0.2 returns the following error:
The current scope already contains a variable of the name name @ line 11, column 17. _id name ^ unable to resolve class _id @ line 11, column 17. _id name
Replacing _id with id or '_id' solves the problem
Can someone please explain why this error occurs with 3.0.2 but not with 2.5.7?