title: resttemplate.exchange return value in raw JSON string
body: <p>I would like to retrieve the return value of this statement in raw JSON string in order to determine mismatching fields in the classes that are annotated with Jackson.</p>
  
  <p>I have checked the following link: </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/47104149/spring-resttemplate-get-raw-json-string">Spring restTemplate get raw json string</a></p>
  </blockquote>
  
  <p>However, in the code snippet in the given link did not work for me because I'm sending a GET request to a Mock service that is currently running on in my computer. Mock service successfully works when I call it as the following code snippet. The problem is the mismatching fields. I also should add HttpMethod.GET and httpEntity fields into my call so that the given link's solution does not work for me.</p>
  
  <p>Here is the code snippted that I would like to retrieve its return value as JSON string:</p>
  
  <pre><code>        ResponseEntity&lt;Sms&gt; smsResponseEntity = restTemplate.exchange(
              createURLWithPort("/customer/sms/905469006108?StartDate=2019-02-05&amp;EndDate=2020-01-06"),
              HttpMethod.GET,
              httpEntity,
              Sms.class);
  </code></pre>
  
  <p>The createUrlWithPort function is given below:</p>
  
  <pre><code>private String createURLWithPort(String uri) {
      return "http://localhost:" + port + uri;
  }
  </code></pre>
  
  <p>Below is the code snippet that I have tried but did not work due to missing httpEntity and HttpMethod.GET </p>
  
  <pre><code> final String response = restTemplate.getForObject("http://localhost:8080/customer/sms/905469006108?StartDate=2019-01-05&amp;EndDate=2020-01-06", String.class);
  </code></pre>
  
  <p>Below,the error is given when I call the previous code snippet:</p>
  
  <pre><code>org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/customer/sms/905469006108": Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
  
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670)
      at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:311)
      at org.springframework.boot.test.web.client.TestRestTemplate.getForObject(TestRestTemplate.java:214)
      at com.vodafone.customer.CustomerIntegrationTest.testRetrieveSmsDataBetweenDates_ReturnsHttp200(CustomerIntegrationTest.java:54)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
      at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
  </code></pre>
  
  <p>I can add any necessary information so please comment if there is any need.</p>
  
  <p>Thanks!</p>