While upgrading a Grails 4 application to Grails 5, I encountered a failure in one of the json views (.gson file) when specifying a field having an empty map. In Grails 4, this worked fine, but in Grails 5 I have to put parentheses around the empty map literal, or the render call fails saying that there is no property of the view class with that name.
I wrote the following unit test to reproduce the behavior:
import grails.plugin.json.view.test.JsonRenderResult
import grails.plugin.json.view.test.JsonViewTest
import spock.lang.Specification
class GrailsViewsCollectionsSpec extends Specification implements JsonViewTest {
void "test value rendering in json views"() {
when: "A gson view is rendered"
JsonRenderResult result = render("""json {
foo null
bar false
baz 0
cheese "is good"
hello([])
world([:])
}""")
then:
result.json.toString() == "{foo=null, bar=false, baz=0, cheese=is good, hello=[], world={}}"
}
}
In Grails 4, I can get away with world [:]
, but in Grails 5, it needs to be world([:])
.
What changed that causes this syntax to become less groovy?