> 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/ix.-how-to-guides/76.-spring-mvc/76.1-write-a-json-rest-service.md).

# 76.1 编写JSON REST服务

只要添加的有Jackson2依赖，Spring Boot应用中的任何`@RestController`默认都会渲染为JSON响应，例如：

```java
@RestController
public class MyController {

    @RequestMapping("/thing")
    public MyThing thing() {
            return new MyThing();
    }

}
```

只要`MyThing`能够通过Jackson2序列化（比如，一个标准的POJO或Groovy对象），默认[localhost:8080/thing](http://localhost:8080/thing)将响应一个JSON数据。有时在浏览器中你可能看到XML响应，因为浏览器倾向于发送XML accept headers。
