title: How to read Gzipped payload in a POST request in SpringBoot
body: <p>I need to read gzipped json payload in a POST request in my SPringBoot app which accepts json data. How to do that in order to keep the application generic as there may be other clients in future sending data in plain json or other compression formats? I suppose this should be handled by the server itself so is there any way to instruct the embedded Tomcat to unzip the payload? </p>
  
  <p>My SpringBoot application runs on embedded Tomcat 9.0.17.</p>
  
  <p>The controller accepts JSON payload in a POST request. </p>
  
  <pre><code>@RequestMapping(value = "/update/v1", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
      public ResponseEntity&lt;String&gt; receiveUpdates(@RequestBody String update) {
  
  </code></pre>
  
  <p>We recently changed our content provider and the new one is sending payload in "gzip" format (with header content-encoding=gzip) and without any content-type header. As a result it gives the following error</p>
  
  <pre><code>'error': 'Unsupported Media Type', 'message': "Content type '' not supported"
  </code></pre>
  
  <p>If I change my consume type to MediaType.ALL_VALUE, my controller starts receiving the request but the payload itself is gzipped. I can handle it in my service layer but that would make it specific to gzipped data.</p>
  
  <p>This problem could be solved by introducing a Filter to handle gzipped payload as mentioned <a href="https://stackoverflow.com/questions/20507007/http-request-compression#answer-20576628">here</a> and <a href="https://stackoverflow.com/questions/21410317/using-gzip-compression-with-spring-boot-mvc-javaconfig-with-restful">here</a>.</p>
  
  <p>But I believe there should be a way to instruct the Tomcat to handle this and serve unzipped data.</p>