O'Reilly logo

Instant GSON by Sandeep Kumar Patel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Quick start – creating your first JSON in GSON

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.

Step 1 – instantiating GSON

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

The default approach

In this approach, the GSON class object can be instantiated using the new keyword. This approach creates a gsonobject instance without any setting.

The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required