> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/27.-developing-web-applications/27.1.-the-spring-web-mvc-framework/27.1.2.-httpmessageconverters.md).

# 27.1.2. HttpMessageConverters

Spring MVC使用`HttpMessageConverter`接口转换HTTP请求和响应。合适的默认配置可以开箱即用，例如对象自动转换为JSON（使用Jackson库）或XML（如果Jackson XML扩展可用，否则使用JAXB），字符串默认使用`UTF-8`编码。

可以使用Spring Boot的`HttpMessageConverters`类添加或自定义转换类，如下所示：

```java
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.*;
import org.springframework.http.converter.*;

@Configuration
public class MyConfiguration {

    @Bean
    public HttpMessageConverters customConverters() {
        HttpMessageConverter<?> additional = ...
        HttpMessageConverter<?> another = ...
        return new HttpMessageConverters(additional, another);
    }
}
```

上下文中出现的所有`HttpMessageConverter` bean都将添加到converters列表。你可以通过这种方式覆盖默认的转换器列表（converters）。
