Convert Java Object to Json using GSON
In this tutorial, we will convert the Java object to JSON using the GSON library. Consider the following steps to convert the Java object to JSON.
1. Create a maven project in eclipse and use pom.xml to add GSON dependencies.
2. Create a Plain Old Java Object (POJO) that is to be converted into Json. Consider the following java code to create the java object.
3. Create a java class that uses Gson class to convert the Company object to Json.
4. We will get the JSON object upon executing the ConvertJSON class. The generated JSON string is given below.
Next TopicConvert XML to JSON in Java