### 65.2. 编写一个XML REST服务 如果classpath下存在Jackson XML扩展(jackson-dataformat-xml),它会被用来渲染XML响应,示例和JSON的非常相似。想要使用它,只需为你的项目添加以下的依赖: ```xml com.fasterxml.jackson.dataformat jackson-dataformat-xml ``` 你可能也想添加对Woodstox的依赖。它比JDK提供的默认Stax实现快很多,并且支持良好的格式化输出,提高了namespace处理能力: ```xml org.codehaus.woodstox woodstox-core-asl ``` 如果Jackson的XML扩展不可用,Spring Boot将使用JAXB(JDK默认提供),不过你需要为MyThing添加额外的注解`@XmlRootElement`: ```java @XmlRootElement public class MyThing { private String name; // .. getters and setters } ``` 想要服务器渲染XML而不是JSON,你可能需要发送一个`Accept: text/xml`头部(或使用浏览器)。