In this section, you will learn about the top features supported by the GSON library. You will also learn about how to implement these features.
Objects in GSON are referred as types of JsonElement:
The GSON library can convert any user-defined class objects to and from the JSON representation. The Student
class is a user-defined class, and GSON can serialize any Student
object to JSON.
The Student.java
class is as follows:
public class Student { private String name; private String subject; privateint mark; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public int getMark() { return mark; } public void setMark(int mark) { this.mark = mark; } }
The code for JavaObjectFeaturesUse.java
is as follows:
import com.google.gson.Gson; importcom.packt.chapter.vo.Student; public...