title: Spring REST Template for Byte
body: <p>I am fetching the byte array using spring framework rest template,
  But I also need to fetch the Mediatype of this byte .</p>
  
  <p>The mediaType of this bytearray can be of any type.</p>
  
  <p>The code used now for fetching byte is below.</p>
  
  <pre><code>   HttpHeaders headers = new HttpHeaders();
     headers.setAccept(Collections.singletonList(MediaType.valueOf("application/pdf")));
     ResponseEntity&lt;byte[]&gt; result = restTemp.exchange(url, HttpMethod.GET, entity, byte[].class,documentId);
  </code></pre>
  
  <p>The above code will fetch only pdf content type.</p>
  
  <p>How to set the contentType to accept any generic MediaType because the service at the other end is providing any random MediaType for the byteArray.</p>
  
  <p>Could someone please suggest how the MediaType can be fetched.</p>
  
  <p>Any suggestions are welcome..</p>