title: Grails cannot cast JSON array to HashMap
body: <p>I have the following JSON (stored as a String in Groovy):</p>
  
  <pre><code>{
      "isFizz": "true",
      "buzzProperties": [
          {
              "foo": "bar"
          },
          {
              "widget": 35
          }
      ],
      "name": "dummy1"
  }
  </code></pre>
  
  <p>In my Grails controller I have the following method that handles this JSON as an HTTP request and attempts to read the JSON into Groovy vars:</p>
  
  <pre><code>Stuff register() {  
      def jsonObject = request.JSON
      Stuff stuff = new Stuff()
      stuff.isFizz                    = jsonObject.isFizz
      stuff.buzzProperties            = jsonObject.buzzProperties             // stuff.buzzProperties is a HashMap
      stuff.name                      = jsonObject.name
  
      stuff
  }
  </code></pre>
  
  <p>When the controller method executes (when it receives a request) I get the following exception:</p>
  
  <pre><code>Cannot cast object '[{"foo":"bar"},{"widget":35}]' with class 'org.codehaus.groovy.grails.web.json.JSONArray' to class 'java.util.Map' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Map(org.codehaus.groovy.grails.web.json.JSONObject, org.codehaus.groovy.grails.web.json.JSONObject). Stacktrace follows:
      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[{"foo":"bar"},{"widget":35}]' with class 'org.codehaus.groovy.grails.web.json.JSONArray' to class 'java.util.Map' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Map(org.codehaus.groovy.grails.web.json.JSONObject, org.codehaus.groovy.grails.web.json.JSONObject)
  </code></pre>
  
  <p>I checked the JSON against <a href="http://jsonlint.com/" rel="nofollow">JSON lint</a> and it is perfectly valid JSON. What's going on here?</p>