71.1 Write a JSON REST service
Any Spring @RestController
in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath. For example:
_@RestController_ public class MyController { _@RequestMapping("/thing")_ public MyThing thing() { return new MyThing(); } }
As long as MyThing
can be serialized by Jackson2 (e.g. a normal POJO or Groovy object) then [localhost:8080/thing](http://localhost:8080/thing)
will serve a JSON representation of it by default. Sometimes in a browser you might see XML responses because browsers tend to send accept headers that prefer XML.