title: Consuming Spring Hateoas Restservice with RestTemplate
body: <p>I have two applications, one is called <strong>bar</strong>, what provides me resources in HAL format. The other is <strong>bcm</strong> to consume that service.</p>
  
  <p>Example of response <strong>bar</strong> looks like this:</p>
  
  <pre><code>[
      {
          "name":"Brenner/in",
          "_links":{
              "self":{
                  "href":"..host/bbsng-app-rest/betrieb/15"
              }
          }
      },
      {
          "name":"Dienstleistungshelfer/in HW",
          "_links":{
              "self":{
                  "href":"..host/bbsng-app-rest/betrieb/4"
              }
          }
      },
      {
          ...
  </code></pre>
  
  <p>Now I try to consume that from <strong>bcm</strong> using Spring RestTemplate. My Solution works, but I am not happy with that solution somehow and I guess there is a more clean way. </p>
  
  <p>My Client-Code consuming RestService looks like:</p>
  
  <pre><code>@Autowired private RestTemplate template;
  
  @Override
  @SuppressWarnings("unchecked")
  public BerufListe findeAlleBerufe() {
      final BerufListe berufListe = new BerufListe();
  
      final ResponseEntity&lt;List&gt; entity = template.getForEntity(LinkUtils.findBeruf(), List.class);
  
      if (OK.equals(entity.getStatusCode())) {
          final List&lt;LinkedHashMap&gt; body = entity.getBody();
          for (final LinkedHashMap map : body) {
              final LinkedHashMap idMap = (LinkedHashMap) map.get("_links");
              String id = remove(String.valueOf(idMap.get("self")), "href=");
              id = remove(id, "{");
              id = remove(id, "}");
              final String name = String.valueOf(map.get("name"));
              final Beruf beruf = new Beruf(id, name);
              berufListe.add(beruf);
          }
      }
  
      return berufListe;
  }
  </code></pre>
  
  <p>There are few ugly code as you see. One of them is, that I don't have any generics for my collections. The other point, I get the Resource_ID very complicated, and I use StringUtils.remove many times to extract the self url. </p>
  
  <p>I am sure there must be a more convenient way to consume HAL-Response by Spring. </p>
  
  <p>Thanks you.</p>