0

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?

0

1 Answer 1

1

Part of Grails 5 was upgrading to Apache Groovy 3.

Alpha versions of Groovy 3 incorrectly let you leave off the brackets when printing empty maps, but they are now required, e.g println([:]).

Refs:
Grails Blog -> Grails Framework Exciting Updates -> Announcing Grails 5!.

Release notes for Groovy 3.0 -> Other breaking changes

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.