title: How to test a rest service returning boolean in response using TestRestTemplate
body: <p>I have a rest service written using Spring Boot as below:</p>
  
  <pre><code>@RestController
  class MyBankingController{
  
  @GetMapping("/getCards")
  public SomePOJO getCards(){}
  
  @GetMapping("/cardPresent")
  public boolean isCardPresent(@RequestParam(value = "username") String 
  username){
  
   //calls service layer to return primitive true or false
  }
  }
  </code></pre>
  
  <p>Below is my test class:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(classes = MyBankingApplication.class, webEnvironment = 
  SpringBootTest.WebEnvironment.RANDOM_PORT)
  public class MyBankingControllerIT {
  
  private MyBankingController myBankingController;
  private TestRestTemplate restTemplate;
  private static final String BASE_URL = "/company/cards";
  HttpHeaders headers = new HttpHeaders();
  String username = "1234";
  
  @Autowired
  private MyBankingService myBankingService;
  
  @LocalServerPort
  private int port;
  
  @Before
  public void setUp() throws Exception {
  
      myBankingController = new MyBankingController(myBankingService);
  
      restTemplate = new TestRestTemplate();
  }
  
  @Test
  public void testIsCardPresent() throws JSONException {
      String url = BASE_URL+"cardPresent?username="+username;
  
      HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(null, headers);
  
      ResponseEntity&lt;Boolean&gt; response = restTemplate.exchange(
              createURLWithPort(url),
              HttpMethod.GET, entity, Boolean.class);
  
      assertTrue(response.getBody());
  }
  
  private String createURLWithPort(String uri) {
      return "http://localhost:" + port + uri;
  }
  }
  </code></pre>
  
  <p>I am unable to test this boolean return type. I have tried a couple of different things but it doesn't work. I am getting the below error. </p>
  
  <pre><code>org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of java.lang.Boolean out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.Boolean out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]
  </code></pre>
  
  <p>Please note that the above code is just a customized version of the actual code and that at the moment it is not possible to change the return type or the controller. 
  Could you be able to tell me how to test this?</p>