Spring Boot RESTful web service JSON example

Spring Boot comes with all the needed components for creating RESTful web services. Here we will see how easily we can build a simple Spring Boot application which will provide web services for CRUD operations i.e. Create, Retrieve, Update and Delete operations using HTTP POST, GET, PUT and DELETE method respectively. To keep the application simple, we will not use any database. Instead just use a HashMap to store the data objects through a Service layer class.

Spring Boot JSON format date using JsonSerialize and JsonFormat

While providing JSON data through Spring Boot or Spring web services, we might have situation where the JSON data contains Date data. By default, the dates are not formatted in human readable format. However, there are ways to format the dates as we want. Here we will see use of two annotations: JsonSerialize JsonFormat Let us see the source code how we can use these annotations. 1. build.

Parse json string using Google Gson

Google Gson is very popular library to convert JSON to object and vice versa. The formJson(…) and toJson(…) are the two main APIs for the same. In this example we will see how to perform following JSON parsing operations using those APIs. 1. Convert a object to JSON string 2. Convert a list of objects to JSON string 3. Parse JSON string to convert to object 4. Parse JSON string to convert to List of objects Like the other examples, I am using gradle as build system.