title: java object to json object to javascript object
body: <p>I am trying to implement the jQuery autocomplete custom data and display. Right now I'm using just the regular autocomplete. My problem is converting the json array of json objects to an array of javascript objects. Could someone please point me in the right direction. Here is what I currently have for the standard autocomplete.</p>
  
  <p>javascript:</p>
  
  <pre><code>$('input[type=radio][name=transaction]').change(function(){
      console.log($('input[type=radio][name=transaction]:checked').val());
      $.ajax({                
          type: "post",
          async: false,
          url: "/autocomplete",
          contenttype: "application/json; charset=utf-8",
          datatype: "json",
          data: "transaction="+$('input[type=radio][name=transaction]:checked').val(),
          success: function (data)
          {
              if($('input[type=radio][name=transaction]:checked').val() == "sell")
                  {
                      theSymbols = JSON.parse(data);
                  }
              else
                  {
                      theSymbols = data;
                  }
          },
          error: function (bad)
          {
              alert("Autocomplete failed.");
          }
      });
      if($('input[type=radio][name=transaction]:checked').val() == "sell")
          {
              $("#symbol").autocomplete(
              {
                minLength: 0,
                source: theSymbols,
                focus: function(event, ui) {
                  $("#symbol").val(ui.item.value);
                  return false;
                },
                select: function(event, ui)
                {
                  $("#symbol").val( ui.item.value);
                  $("#sharesOwn").html( ui.item.shares);
                  $("#sharesText").show();
                  return false;
                }
              })
              .autocomplete("instance")._renderItem = function(ul, item) 
              {
                return $("&lt;li&gt;")
                  .append("&lt;a&gt;" + item.label + "&lt;br&gt;&lt;span class='acFormat'&gt;" + item.desc + "&lt;/span&gt;&lt;/a&gt;")
                  .appendTo(ul);
              };
          }
      else
          {
              $("#symbol").autocomplete({source: theSymbols});
          }
  </code></pre>
  
  <p>java:</p>
  
  <pre><code>ArrayList&lt;String&gt; symbols = new ArrayList&lt;String&gt;();                   
  
                      ArrayList&lt;Position&gt; positionList = new ArrayList&lt;Position&gt;();
                      positionList = PositionDB.getPositions(user.getPortfolioID(), "O");
                      for (Position p : positionList)
                      {
                          String data = "";
                          data = "{";
                          data += "value: " + p.getSymbol();
                          data += ", label: " + p.getSymbol();
                          data += ", desc: " + p.getCompName();
                          data += ", shares: " + p.getShares();
                          data += "}";    
                          symbols.add(data);
                      }    
  
  
                  Gson gson = new Gson();
                  JsonElement syms = gson.toJsonTree(symbols, new TypeToken&lt;List&lt;String&gt;&gt;() {}.getType());
                  response.setContentType("application/json; charset=UTF-8");
                  JsonArray jArray = syms.getAsJsonArray();
                  PrintWriter out = response.getWriter();
                  System.out.println(jArray);
                  out.print(jArray);
                  out.flush();
  </code></pre>
  
  <p>Stock object has symbol, company name and price.</p>
  
  <p>I'm having problems creating the JSON array or objects to pass to my javascript. Right now it outputs as if it were a js array of objects but keys are showing up in the textbox, along with the values so the autocomplete must be seeing it as a string, which means that I can't build it as a string in java so I need a different way. Ideas?</p>
  
  <p>Thank you.</p>