How to convert Java object to JSON and JSON to Java object with Gson?
In this section, we will show you h ow to convert Java object to JSON and JSON to Java object with Gson. Note Google Gson is a simple Java-based library to serialize Java objects to JSON and vice versa. It is an open-source library developed by Google. Note JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. JSON is built on two structures: A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. 1. Download Gson < dependency > < groupId >com.google.code.gson</ groupId > < artifactId >gson</ artifactId > < version >2.9.0</ version > </ dependency > 2. Java Objects to JSON A User POJO, later uses this for conversion. User.java public class User { private Long id ; private Str