title: Spring boot Invalid UTF-8 middle byte on specific machine when sending request with Hebrew
body: <p>I am using Spring boot mvc and I have an issue that is reproduced only on my staging machine, but works fine locally.</p>
  
  <p>I am sending the following JSON reqeust (notice Hebrew chars under "whatever" field):</p>
  
  <pre><code>{
   "messageInitiaterId":"0542258808",
   "destinationId":"0544556543",
   "whatever":"משהו",
   "pushToken":"e2eeb632-8c2c-4ad2-a163-cfeb671d1955",
   "androidVersion":"7.1.1",
   "deviceModel":"huawei nexus 6p",
   "appVersion":"1.42"
  }
  </code></pre>
  
  <p>Locally, it returns a response and all is well. On the staging machine, this is the response returned:</p>
  
  <pre><code>{
    "timestamp": 1485591099485,
    "status": 400,
    "error": "Bad Request",
    "exception":          
  
      "org.springframework.http.converter.HttpMessageNotReadableException",
    "message": "Could not read document: Invalid UTF-8 middle byte 0x3f\n at [Source: java.io.PushbackInputStream@6996e7d; line: 4, column: 17]; nested exception is com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 middle byte 0x3f\n at [Source: java.io.PushbackInputStream@6996e7d; line: 4, column: 17]",
    "path": "/v1/IsRegistered"
  
  }
  </code></pre>
  
  <p>Currently using Postman to reproduce this. The header on the request is: </p>
  
  <pre><code>"Content-Type":"application/json; charset=UTF-8"
  </code></pre>
  
  <p>I also tried to add the Hebrew language to the machine itself, which is running Windows 8, but it did not seem to make a difference.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong><em>EDIT</em>:</strong></p>
  
  <p>This is the controller, adding the suggested <code>MediaType</code> but still getting the same error:</p>
  
  <pre><code>@Controller
  public class IsRegisteredController extends AbstractController {
  
  private final IsRegisteredLogic logic;
  
  @Autowired
  public IsRegisteredController(IsRegisteredLogic logic) {
      this.logic = logic;
  }
  
  @ResponseBody
  @RequestMapping(value = "/v1/IsRegistered", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public Response&lt;UserDTO&gt; isRegistered(@Valid @RequestBody IsRegisteredRequest request, HttpServletResponse response) {
      return logic.execute(request, response);
  }
  }
  </code></pre>
  
  <p><strong><em>EDIT2:</em></strong></p>
  
  <p>Tried the suggestions below, as well as others I found online, all of which did not make a difference. This seems to be a more difficult problem than I thought.</p>
  
  <p>Added to application.properties the following fields:</p>
  
  <pre><code>spring.http.encoding.charset=UTF-8
  spring.http.encoding.enabled=true
  spring.http.encoding.force=true
  spring.datasource.connectionproperties=useUnicode=true;characterEncoding=utf-8;
  </code></pre>
  
  <p>As well as the following beans:</p>
  
  <pre><code>@Bean
  public TomcatConnectorCustomizer tomcatConnectorCustomizer() {
      return connector -&gt; connector.setURIEncoding("UTF-8");
  }
  
  @Bean
  public Filter characterEncodingFilter() {
      CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
      characterEncodingFilter.setEncoding("UTF-8");
      characterEncodingFilter.setForceEncoding(true);
      return characterEncodingFilter;
  }
  </code></pre>
  
  <p>All is to no avail. What's going on here? Surely Spring boot can handle Hebrew chars in requests...</p>