title: Use the ResponseEntity<List<String>> after Ajax GET request
body: <p>I work with <code>Java/Spring MVC RESTful</code> web project and this is the method I use to get a <code>List&lt;String&gt;</code> from the backend, </p>
  
  <pre><code>@RequestMapping(value = "/transactions/{walletId}", method = RequestMethod.GET)
      public ResponseEntity&lt;List&lt;String&gt;&gt; readAllTransactionsByWalletId(@PathVariable("walletId") Long walletId) {
  
          WalletModel walletModel = getWalletModel(walletId);
  
          if (Objects.isNull(walletModel)) {
              return new ResponseEntity&lt;List&lt;String&gt;&gt;(HttpStatus.NOT_FOUND);
          }
  
          List&lt;Transaction&gt; transactions = walletModel.getTransactions();
  
          List&lt;String&gt; list = new ArrayList&lt;&gt;();
  
          for (Transaction transaction : transactions) {
              list.add(walletModel.addTransactionHistory(transaction));
          }
  
          return new ResponseEntity&lt;List&lt;String&gt;&gt;(list, HttpStatus.OK);
      }
  </code></pre>
  
  <p>I would like to make an <code>Ajax request</code> from the client to the method and use the data. The <code>HTML</code> page is like something, </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;meta name="description" content=""&gt;
      &lt;meta name="author" content=""&gt;
  
      &lt;title&gt;Wallet Transactions&lt;/title&gt;
  
      &lt;!-- Bootstrap Core CSS --&gt;
      &lt;link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"&gt;
  
      &lt;!-- Theme CSS --&gt;
      &lt;link href="css/main.css" rel="stylesheet"&gt;
  
      &lt;!-- Custom Fonts --&gt;
      &lt;link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css"&gt;
      &lt;link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet"
            type="text/css"&gt;
  
      &lt;!--JavaScript sources--&gt;
      &lt;script src="vendor/jquery/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="vendor/bootstrap/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
      &lt;!-- Plugin JavaScript --&gt;
      &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"&gt;&lt;/script&gt;
      &lt;script src="js/main.js"&gt;&lt;/script&gt;
  
      &lt;!-- custom JavaScript for the page to execute --&gt;
      &lt;script&gt;
  
          // set as the global variable in the context
          var walletName, walletAddress, walletCurrency;
          var baseUrl = "http://localhost:8080";
  
          // generic request function interact with the RESTful methods
          function request() {
              $.ajax({
                  // url: url,
                  // we use localhost for the testing
                  url: baseUrl + url,
                  method: method,
                  data: data
              })
          };
  
          // extract the value from the parameter and the URL
          // If the UR is like "/WalletClient/sendMoney.html?walletId=12&amp;walletName=puut"
          // after calling the getParameterByName("walletId") will return the value of 12
          // where the URL is in default value
          function getParameterByName(name, url) {
  
              // if the url value is not provided, assume
              // we need to use the url of the page
              if (!url) {
                  url = window.location.href;
              }
  
              name = name.replace(/[\[\]]/g, "\\$&amp;");
              var regex = new RegExp("[?&amp;]" + name + "(=([^&amp;#]*)|&amp;|#|$)"),
                  results = regex.exec(url);
  
              if (!results) return null;
              if (!results[2]) return '';
  
              return decodeURIComponent(results[2].replace(/\+/g, " "));
          }
  
  
          var parameterName = "walletId";
          var urlName = window.location.href;
  
          // extract the wallet Id from the URL
          var walletId = getParameterByName(parameterName, urlName);
  
  
          $(document).ready(function () {
  
              // fill out the Id with the dummy values
              $("#currency").text("currency");
              $("#address").text("address");
              $("#balance").text("balance");
              $("#transactions").text("transactions");
  
  
              // curl -G http://localhost:8080/rest/transactions/1 | json with GET request
  
  //            @RequestMapping(value = "/transactions/{walletId}", method = RequestMethod.GET)
  //            public ResponseEntity&lt;List&lt;String&gt;&gt; readAllTransactionsByWalletId(@PathVariable("walletId") Long walletId) {
  //
  //                // some code
  //            }
  
              request("/rest/transactions/" + walletId, "GET").done(function (data) {
  
                  // we have the data with is in the form of ResponseEntity&lt;List&lt;String&gt;&gt;
              });
          });
  
      &lt;/script&gt;
  &lt;/head&gt;
  
  
  &lt;body id="page-top" class="index"&gt;
  
  
  &lt;!-- get all the transactions info here--&gt;
  &lt;div id="show_transactions"&gt;
      &lt;div&gt;
          &lt;h4&gt;Wallet Name = &lt;span id="walletName"&gt;&lt;/span&gt;&lt;/h4&gt;
      &lt;/div&gt;
  
      &lt;div&gt;
          &lt;h4&gt;Currency = &lt;span id="currency"&gt;&lt;/span&gt;&lt;/h4&gt;
      &lt;/div&gt;
  
      &lt;div&gt;
          &lt;h4&gt;Address = &lt;span id="address"&gt;&lt;/span&gt;&lt;/h4&gt;
      &lt;/div&gt;
  
      &lt;div&gt;
          &lt;h4&gt;Balance = &lt;span id="transactions"&gt;&lt;/span&gt;&lt;/h4&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Inside the <code>request</code>, I expect the <code>GET</code> method would return the <code>List&lt;String&gt;</code> and I want to iterate over it and fill inside the <code>&lt;div&gt;</code></p>
  
  <pre><code>&lt;div&gt;
      &lt;h4&gt;Balance = &lt;span id="transactions"&gt;&lt;/span&gt;&lt;/h4&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>How would I be able to to that?</p>
  
  <p>UPDATE</p>
  
  <p>I have no real data now, but the <code>cURL</code> requests return, </p>
  
  <p><a href="https://i.stack.imgur.com/P9U48.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P9U48.png" alt="enter image description here"></a></p>
  
  <p>UPDATE 2</p>
  
  <p>I modified the code to fill up some generated data and it still returns <code>[]</code>. I use <code>IntelliJ</code> and have cleaned the <code>Cache</code> and restarted. The code -</p>
  
  <pre><code>        List&lt;String&gt; test = new ArrayList&lt;&gt;();
  
          test.add("Berlin");
          test.add("Miami");
          test.add("Seattle");
          test.add("Copenhagen");
  
         return new ResponseEntity&lt;List&lt;String&gt;&gt;(test, HttpStatus.OK);
  </code></pre>
  
  <p>Any idea why does this happening?</p>