title: Code works but test fails with code 415 when using custom deserializer
body: <p>I have an endpoint that receives a Json and deserializes it into a DTO object using a custom deserializer. <strong>This works without any problem.</strong> The problem comes when I ran the tests that were working before. The tests are throwing the following error: 415 &quot;Content type 'application/json; charset=UTF-8' not supported&quot;. I narrowed it down to the @JsonDeserialize annotation in my DTO class. If I remove the @JsonDeserialize annotation the error doesn't show (but obviously then the rest of the logic fails). Is there any config needed to make the test work with the custom deserializer?
  Notes:</p>
  <ul>
  <li>I checked that the request json is not the problem</li>
  <li>I tried playing with content-type without success</li>
  <li>I checked that all my jackson dependencies have the same version.</li>
  </ul>
  <p>The test:</p>
  <blockquote>
  <pre><code>@Test
  public void do_stuff_null_property() throws Exception {
      MyRequest request = createMyRequest();
      request.setProperty(null);
  
      mockMvc.perform(post(&quot;/dostuff&quot;)
              .accept(&quot;application/json; charset=UTF-8&quot;)
              .header(&quot;Content-Type&quot;, &quot;application/json; charset=UTF-8&quot;)
              .content(mapper.writeValueAsString(request)))
              .andExpect(status().isBadRequest());
  
  }
  </code></pre>
  </blockquote>
  <p>The endpoint looks like this:</p>
  <blockquote>
  <pre><code>@RequestMapping(value = &quot;/dostuff&quot;, method = RequestMethod.POST)
  public String doStuffEndpoint(HttpServletRequest request,
                                       ModelMap model,
                                       RedirectAttributes redirectAttributes,
                                       @Valid @RequestBody MyRequest request) {
    
      //dostuff
  
    return &quot;page&quot;;  }
  </code></pre>
  </blockquote>
  <p>I reduced the deserializer to the minimum but the error still arises:</p>
  <blockquote>
  <pre><code>public class MyDeserializer extends JsonDeserializer&lt;MyRequest&gt; {
  
  public MyDeserializer() {
      super();
  }
  
  @Override
  public MyRequest deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException,
   JsonProcessingException {    
       return new MyRequest(); 
   } 
   }
  </code></pre>
  </blockquote>
  <p>and the DTO:</p>
  <blockquote>
  <pre><code> @JsonDeserialize(using = MyDeserializer.class) 
   public class MyRequest{
  
     private Integer whatever;
  
     //SETTERS,GETTERS AND EMPTY CONSTRUCTOR
  
   }
  </code></pre>
  </blockquote>