Working with JSON
So far, our APIs have been working using JSON,
from return JSON
objects as results, to accepting JSON objects in the body of the request. But we need to understand how this works and how we can create and use more complicated JSON objects. In this section, we will review the different mechanisms that Spring provides to handle our JSON requests and responses.
Understanding serialization
In our examples, we have created the Customer
class and we have seen that returning an object of that class in our controller, either directly or through a response entity, it will get converted into JSON. This mechanism is known as serialization, converting an object into a representation, in our case, a JSON object.
Spring is used for archiving this Jackson
, a widely known library to handle JSON objects in Java. You could find more information about that library on their website: https://github.com/FasterXML/jackson.
When we output a Java object, Spring will use internally an ObjectMapper
,...