title: Mapping RestTemplate response to java Object
body: <p>I am using <code>RestTemplate</code> get data from remote rest service and my code is like this.</p>
  
  <pre><code>ResponseEntity&lt;List&lt;MyObject &gt;&gt; responseEntity = restTemplate.exchange(request, responseType);
  </code></pre>
  
  <p>But rest service will return just text message saying no record found if there are no results and my above line of code will throw exception.
  I could map result first to string and later use <code>Jackson 2 ObjectMapper</code> to map to <code>MyObject</code>.</p>
  
  <pre><code>ResponseEntity&lt;String&gt; responseEntity = restTemplate.exchange(request, responseType);
  String jsonInput= response.getBody();
  List&lt;MyObject&gt; myObjects = objectMapper.readValue(jsonInput, new TypeReference&lt;List&lt;MyObject&gt;&gt;(){});
  </code></pre>
  
  <p>But I don't like this approach. Is there any better solution for this.</p>