Reputation: 348
In a fresh grails 4.0.4 application the settings of
grails:
views:
gsp:
codecs:
expression: none
seem to be ignored when deployed as a war file in a Tomcat 8.5.39. (JVM 11.0.7+10-post-Ubuntu-2ubuntu218.04)
Adding this
<head>
...
<script>
var foo = ${[a:23, b:42, c:666] as grails.converters.JSON};
</script>
</head>
to the generated grails-app/views/index.gsp
shows up as
var foo = {"a":23,"b":42,"c":666};
when running grails run-app
or even grails prod run-app
(!), but is encoded as
var foo = {"a":23,"b":42,"c":666};
in the packaged (grails prod war
) deployed war file.
The build.gradle
was unmodified, except for changing
compile "org.grails.plugins:cache"
to this
compile("org.grails.plugins:cache") {
exclude module:'groovy-all'
}
Is this a bug or am I using the codecs settings wrong? Maybe there is a plugin overwriting this settings (like here https://github.com/grails/grails-core/issues/10722) but i cannot find any other yml files. Any help is appreciated!
Upvotes: 1
Views: 251
Reputation: 66
It works like a charm in Grails 4.0.3. Seems it is broken in Grails 4.0.4 ...
Maybe the problem came with the new Groovy Page Compiler Task. The config file (aka application.yml
) variable here is never used. But that's only an assumption after quick investigation with too little coffee ;-)
Some helper TagLib like this:
import grails.converters.JSON
class FooTagLib {
static defaultEncodeAs = [taglib:'none']
static namespace = "foo"
def json = { attrs, body ->
out << raw(attrs.data as JSON)
}
}
Usage:
var foo = <foo:json data="[a:23, b:42, c:666]"/>
Upvotes: 2