Menu

Groovy from string to object issue

Help
2008-02-17
2013-04-29
  • Scott F. Walter

    Scott F. Walter - 2008-02-17

    I'm trying something simple with Groovy and JSON-lib:

    import net.sf.json.*
    def fromList = "[{name:'scott'}, {name:'mike'}]" as JSONArray

    however I am getting this error:

    Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[{name:'scott'}, {name:'mike'}]' with class 'java.lang.String' to class 'net.sf.json.JSONArray'
        at test.run(test.groovy)
        at test.main(test.groovy)

    Any ideas?

     
    • aalmiray

      aalmiray - 2008-02-17

      Scott,

      Starting from 2.2.1 custom metaClasses are no loner registered at startup, you'll have to call
         net.sf.json.groovy.GJson.enhanceClasses()
      before attempting groovy casting.
      I thought the info was on the site but the gapi docs are missing, I'll make sure the docs get
      updated.

      Cheers,
      Andres

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.