I am converting existing Grails 2.5.6 project to Grails 3.3.11.
With my existing application (Grails 2.5.6), the plugin descriptor is having code like below:
def doWithApplicationContext = { applicationContext ->
def config = applicationContext.grailsApplication.config
def key = config.property.key
key.put(Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"])
}
This code works fine with earlier version of grails. But after I have upgraded to grails 3.3.11 then it throws exception:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
This is at line:
key.put(Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"])
After looking at the type of key i.e. config.property.key it is showing type as org.grails.config.NavigableMap$NullSafeNavigator
.
Which with older version was LinkedHashMap.
property.key is set on application.groovy fine under /grails-app/conf/application.groovy
property.key = [:]
I've also tried setting type of property.key
in plugin descriptor externally to java.util.HashMap
. But it seems like not adopting new type.
What I am doing wrong here?
Instead of trying to do this dynamically with this:
def doWithApplicationContext = { applicationContext ->
def config = applicationContext.grailsApplication.config
def key = config.property.key
key.put(2, [controller: "results", action: "showData", templatePath: "/results/data"])
}
You could define those values in grails-app/conf/plugin.yml
like this:
---
property:
key:
'2':
controller: results
action: showData
templatePath: '/results/data`
EDIT
The question has changed such that the above is no longer valid.
Instead of doing this:
def config = applicationContext.grailsApplication.config
def key = config.property.key
key.put(Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"])
You can simplify that to this:
config.merge([property: [key: [Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"]]]])