title: add MappingJackson2HttpMessageConverter to Spring Boot
body: <p>i want to add my Custom MappingJackson2HttpMessageConverter to Spring Boot . it set successful as Converter but did not use it for converting ...</p>
  
  <p>i see this error just for spring 4.3 and upper. it successful set in spring 4.0.3</p>
  
  <p>How do i correct this converter ???</p>
  
  <p>here is my code</p>
  
  <pre><code>public class ResponseViewEntity&lt;T&gt; extends
      ResponseEntity&lt;ContainerViewEntity&lt;T&gt;&gt; {
  
  private Class&lt;? extends View.Base&gt; view;
  
  public ResponseViewEntity(HttpStatus statusCode) {
      super(statusCode);
  }
  
  public ResponseViewEntity(T body, HttpStatus statusCode) {
      super(new ContainerViewEntity&lt;T&gt;(body, View.Base.class), statusCode);
  }
  
  public ResponseViewEntity(T body, Class&lt;? extends View.Base&gt; view, HttpStatus statusCode) {
      super(new ContainerViewEntity&lt;T&gt;(body, view), statusCode);
  }
  </code></pre>
  
  <p>Converter : </p>
  
  <pre><code>public class JsonViewMessageConverter extends
      MappingJackson2HttpMessageConverter {
  
  private ObjectMapper objectMapper = new HibernateAwareObjectMapper();
  
  protected Object readInternal(Class&lt;?&gt; clazz, HttpInputMessage inputMessage)
          throws IOException, HttpMessageNotReadableException {
      JavaType javaType = getJavaType(clazz);
      try {
          return objectMapper.readValue(inputMessage.getBody(), javaType);
      } catch (JsonProcessingException ex) {
          throw new HttpMessageNotReadableException("Could not read JSON: "
                  + ex.getMessage(), (Throwable) ex);
      }
  }
  
  protected void writeInternal(Object object, HttpOutputMessage outputMessage)
          throws IOException, HttpMessageNotWritableException {
      if (object instanceof ContainerViewEntity
              &amp;&amp; ((ContainerViewEntity) object).hasView()) {
          writeView((ContainerViewEntity) object, outputMessage);
      } else {
          super.writeInternal(object, outputMessage);
      }
  }
  
  protected void writeView(ContainerViewEntity view,
          HttpOutputMessage outputMessage) throws IOException,
          HttpMessageNotWritableException {
      JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders()
              .getContentType());
      ObjectWriter writer = getWriterForView(view.getView());
      JsonGenerator jsonGenerator = writer.getFactory().createGenerator(
              outputMessage.getBody(), encoding);
      try {
          writer.writeValue(jsonGenerator, view.getObject());
      } catch (IOException ex) {
          throw new HttpMessageNotWritableException("Could not write JSON: "
                  + ex.getMessage(), (Throwable) ex);
      }
  }
  
  private ObjectWriter getWriterForView(Class&lt;?&gt; view) {
      objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
      return objectMapper.writer().withView(view);
  }
  
  protected JavaType getJavaType(Class&lt;?&gt; clazz) {
      return TypeFactory.defaultInstance().constructType(clazz);
  }
  
  public ObjectMapper getObjectMapper() {
      return objectMapper;
  }
  
  protected JsonEncoding getJsonEncoding(MediaType contentType) {
      if (contentType != null &amp;&amp; contentType.getCharset() != null) {
          Charset charset = contentType.getCharset();
          for (JsonEncoding encoding : JsonEncoding.values()) {
              if (!charset.name().equals(encoding.getJavaName()))
                  continue;
              return encoding;
          }
      }
      return JsonEncoding.UTF8;
  }
  
  public void setObjectMapper(ObjectMapper objectMapper) {
      Assert.notNull((Object) objectMapper,
              (String) "ObjectMapper must not be null");
      this.objectMapper = objectMapper;
  }
  </code></pre>
  
  <p>and My config</p>
  
  <pre><code>@Bean
  public JsonViewMessageConverter mappingJackson2HttpMessageConverter() {
      JsonViewMessageConverter jsonConverter = new JsonViewMessageConverter();
      ObjectMapper objectMapper = new HibernateAwareObjectMapper();
      jsonConverter.setObjectMapper(objectMapper);
      return jsonConverter;
  }
  
  @Override
  public void configureMessageConverters(
          List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
      converters.add(mappingJackson2HttpMessageConverter());
  }
  </code></pre>