Creating JSON-based APIs
A key ingredient in building any web application is the ability to provide an API. In the olden days, this was complex and hard to ensure compatibility.
In this day and age, the world has mostly converged on a handful of formats, many based on JSON-based structures.
One of the powerful features of Spring Boot is that when you add Spring Web to a project, as we did at the beginning of this chapter, it adds Jackson to the classpath
. Jackson is a JSON serialization/deserialization library that has been widely adopted by the Java community.
Jackson’s ability to let us define how to translate Java classes back and forth with our preferred flavor of JSON combined with Spring Boot’s ability to autoconfigure things means that we don’t have to lift another finger of setup to start coding an API.
To start things off, we create a new class in the same package we’ve been using throughout this chapter. Call it ApiController
. At the...