In this section, you will learn different ways to instantiate GSON and their significance, followed by a quick example code that shows the basic serialization of wrapper type Java objects.
To use the GSON library, an object of the com.google.gson.Gson
class needs to be instantiated. A GSON object does not maintain any state; this characteristic helps in reusing the GSON object at multiple places.
The GSON library provides two ways for instantiating it:
The default approach
The builder approach with settings
In this approach, the GSON class object can be instantiated using the new
keyword. This approach creates a gsonobject
instance without any setting.