I have a third party API that returns an image as a response in png format.I'm using Rest template to call that API and get the response as Byte[] but I'm getting this exception
There was an unexpected error (type=Bad Request, status=400).JSON parse error: Can not deserialize instance of java.lang.Byte[] out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Byte[] out of START_OBJECT token at [Source: java.io.PushbackInputStream@7c9dac50; line: 1, column: 1]
I have written the following code to get the image using the rest template
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "*/*");
headers.set("Authorization","Bearer "+bearerToken);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
HttpEntity<String> entity = new HttpEntity<String>(headers);
ResponseEntity<Byte[]> response = restTemplate.exchange(endPoint,HttpMethod.GET,entity,Byte[].class);
How to get an image from an API using the rest template in java?