I want to use the ConfigSlurper to write a configuration file to disk, but I get the error:
groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.indexOf() is applicable for argument types: (java.lang.String) values: [.]
The foll开发者_C百科owing example works fine until I uncomment the "aList" part of it. Is there a problem with the serialization of this in the config slurper, or is there an alternative way that I could write this?
def configObj = new ConfigObject()
configObj.testing = [1, 2, 3]
configObj.nested = [ objects : 'wtf' ]
/*configObj.aList[0] =
[
listItem:"000",
subLists:(["ZZ","AB"]),
]*/
print configObj
//serialize it
new File( 'newout.groovy' ).withWriter{ writer ->
configObj.writeTo( writer )
}
Yes, this should work. You only need to initialise the map first like this:
configObj.aList = []
And then use your code
configObj.aList[0] =
[
listItem:"000",
subLists:(["ZZ","AB"]),
]
Alternatively, just in-line the element
configObj.aList = [
[
listItem:"000",
subLists:(["ZZ","AB"]),
]
]
精彩评论