title: Retrieving Array of Object from params on Grails
body: <p>I'm passing an <code>Array</code> on a <code>POST</code> request using an <code>AJAX</code> call, but not a simple one, rather an <code>Array</code> of <code>Object</code>s:</p>
  
  <pre><code>var param = {
      ...,
      branches: {
          0: {
              address: "...",
              telephone: "...",
              fax: "...",
              ...
          },
          ...
          nth: {
              address: "...",
              telephone: "...",
              fax: "...",
              ...
          }
      }
  }
  
  $.ajax({
      type: "POST",
      url: ".../saveTransaction"
      data: param
      success: function(r) {
          ...
      }
  });
  </code></pre>
  
  <p>This is my <code>controller</code></p>
  
  <pre><code>def orderService;
  function saveTransaction() {
      def response = orderService.save(params)
      render response as JSON
  }
  </code></pre>
  
  <p>And this is my <code>service</code>:</p>
  
  <pre><code>def save(params) {
      def branches = params.branches
      println "branches: $branches"
  
      def branches = params.list("branches")
      println "branches: $branches"
  
      branches = params.list("branches[]")
      println "branches: $branches"
  }
  </code></pre>
  
  <p>It does not display what I expect, instead it displays the following:</p>
  
  <pre><code>branches: null
  branches:
  branches: []
  </code></pre>
  
  <p>How can I get these passed <code>branches</code> on the <code>service</code> from the <code>params</code> as an <code>Array</code> / <code>List</code>?</p>
  
  <hr>
  
  <p>After experimenting, I've seen that it is not passed as an <code>object</code> rather as a flat <code>Map</code> having it's accessor as the <code>key</code>, so when I use:</p>
  
  <pre><code>println "branches: " + branches."[0][address]"
  </code></pre>
  
  <p>It prints:</p>
  
  <pre><code>branches: ...
  </code></pre>
  
  <p>Now, my follow-up question is how can I change this behavior to this instead?</p>
  
  <pre><code>println "branches: " + branches[0].address
  </code></pre>