title: How to make a rest api call in java and map the response object?
body: <p>I'm currently developing my first java program who'll make a call to a rest api(jira rest api, to be more especific).</p>
  
  <p>So, if i go to my browser and type the url = 
  "<a href="http://my-jira-domain/rest/api/latest/search?jql=assignee=currentuser()&amp;fields=worklog" rel="nofollow noreferrer">http://my-jira-domain/rest/api/latest/search?jql=assignee=currentuser()&amp;fields=worklog</a>"</p>
  
  <p>I get a response(json) with all the worklogs of the current user. 
  But my problem is, how i do my java program to do this ? 
  Like,connect to this url, get the response and store it in a object ?</p>
  
  <p>I use spring, with someone know how to this with it.
  Thx in advance guys.</p>
  
  <p>Im adding, my code here:</p>
  
  <pre><code>RestTemplate restTemplate = new RestTemplate();
  String url;
  url = http://my-jira-domain/rest/api/latest/search/jql=assignee=currentuser()&amp;fields=worklog
  jiraResponse = restTemplate.getForObject(url,JiraWorklogResponse.class);
  </code></pre>
  
  <p>JiraWorkLogResponse is a simple class with some attributes only.</p>
  
  <p>Edit,
  My entire class:</p>
  
  <pre><code>@Controller
  @RequestMapping("/jira/worklogs")
  public class JiraWorkLog {
  
      private static final Logger logger = Logger.getLogger(JiraWorkLog.class.getName() );
  @RequestMapping(path = "/get", method = RequestMethod.GET, produces = "application/json")
  
      public ResponseEntity getWorkLog() {
  
  
      RestTemplate restTemplate = new RestTemplate();
      String url;
      JiraProperties jiraProperties = null;
  
  
      url = "http://my-jira-domain/rest/api/latest/search?jql=assignee=currentuser()&amp;fields=worklog";
  
      ResponseEntity&lt;JiraWorklogResponse&gt; jiraResponse;
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders = this.createHeaders();
  
  
      try {
          jiraResponse = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity&lt;Object&gt;(httpHeaders),JiraWorklogResponse.class);
  
  
  
      }catch (Exception e){
          return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
      }
  
      return ResponseEntity.status(HttpStatus.OK).body(jiraResponse);
  
  }
  
  
  private HttpHeaders createHeaders(){
      HttpHeaders headers = new HttpHeaders(){
          {
              set("Authorization", "Basic something");
          }
      };
      return headers;
  }
  </code></pre>
  
  <p>This code is returning :
  org.springframework.http.converter.HttpMessageNotWritableException</p>
  
  <p>Anyone knows why ?</p>