title: ArrayList to Json
body: <p>Receive result from query in SessionBean</p>
  <pre><code>public List getUserTransaction(User user, Balancestatus status) {
  return em.createNamedQuery(&quot;Balance.findLastFiveTransaction&quot;).setParameter(&quot;user&quot;, user).setParameter(&quot;status&quot;, status).getResultList();
  </code></pre>
  <p>My query</p>
  <pre><code>select b from Balance b join b.typecategory t where b.user = :user and b.typecategory = t and b.status = :status
  </code></pre>
  <p>Getting data in servlet and passed to Json</p>
  <pre><code>PrintWriter out = response.getWriter();
   
  user = userHandler.userCheck(&quot;mail@mail.com&quot;);
  List&lt;Balance&gt; userTransaction = balance.getUserTransaction(user, outStatus);
  Gson gson = new Gson();
  String json = gson.toJson(userTransaction);
   
  out.write(json);
  </code></pre>
  <p>Try parse using JQuery and output in console</p>
  <pre><code>.............
  $.each(data, function(index, element) {
  console.log(element);
  });
  ..............
  </code></pre>
  <p>and get the error</p>
  <blockquote>
  <p>TypeError: invalid 'in' operand obj
  [Break On This Error]</p>
  <p>typeof length === &quot;number&quot; &amp;&amp; length &gt; 0 &amp;&amp; ( length - 1 ) in obj );</p>
  </blockquote>
  <p>My Json from ArrayList to Json</p>
  <blockquote>
  <p>[{&quot;id&quot;:&quot;7&quot;,&quot;description&quot;:&quot;evil data
  show&quot;,&quot;sum&quot;:666.00,&quot;category&quot;:{&quot;id&quot;:&quot;1&quot;,&quot;name&quot;:&quot;Wallet&quot;},&quot;typecategory&quot;:{&quot;id&quot;:&quot;4&quot;,&quot;name&quot;:&quot;Home&quot;},&quot;user&quot;:{&quot;id&quot;:&quot;1&quot;,&quot;created&quot;:&quot;Jun
  5, 2013 1:44:45
  PM&quot;,&quot;email&quot;:&quot;mail@mail.com&quot;,&quot;pass&quot;:&quot;mail&quot;,&quot;updated&quot;:&quot;Jun 5, 2013
  1:44:45 PM&quot;},&quot;status&quot;:{&quot;id&quot;:&quot;2&quot;,&quot;statusName&quot;:&quot;out&quot;}}
  ...........]</p>
  </blockquote>
  <p>How correct passed ArrayList to Json? Use JBoss AS 7.1</p>