Advertisement
TriggerTG

Untitled

Aug 11th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1.         HttpHeaders headers = new HttpHeaders();
  2.         headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
  3.         httpEntity = new HttpEntity<String>(headers);
  4.  
  5.     public List<OfferedServiceTO> getOfferedServices() {
  6. // Fails with the unrecognized field "service" exception, using the XML document
  7.  
  8. //      return restTemplate.getForObject(
  9. //              dataServiceUriTemplate,
  10. //              OfferedServiceTOList.class,
  11. //              OFFERED_SERVICES
  12. //          );
  13. //      // public class OfferedServiceTOList extends ArrayList<OfferedServiceTO> {}
  14.  
  15.         // Debugging:
  16.         ResponseEntity<String> resp = restTemplate.exchange(
  17.                 dataServiceUriTemplate,
  18.                 HttpMethod.GET, httpEntity,
  19.                 String.class,
  20.                 OFFERED_SERVICES
  21.             );
  22.         String str = resp.getBody();
  23.        
  24.         // If Json, fails with "Problem: abstract types can only be instantiated with additional type information" exception
  25.         ResponseEntity<Source> response = restTemplate.exchange(
  26.                 dataServiceUriTemplate,
  27.                 HttpMethod.GET, httpEntity,
  28.                 Source.class,
  29.                 OFFERED_SERVICES
  30.             );
  31.        
  32.         List<OfferedServiceTO> result = (OfferedServiceTOList) marshaller.unmarshal(response.getBody());
  33.         return result;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement