Reader small image

You're reading from  Instant GSON

Product typeBook
Published inAug 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781783282036
Edition1st Edition
Languages
Right arrow
Author (1)
Sandeep Patel
Sandeep Patel
author image
Sandeep Patel

http://www.packtpub.com/developing-responsive-web-applications-with-ajax-and-jquery/book
Read more about Sandeep Patel

Right arrow

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 builder approach

In this approach, a GSON class object can be created using the GsonBuilder class and the create method:

Gsongson = new GsonBuilder ().create ();

The preceding code calls the create method of GsonBuilder, which returns a Gson object for...

Previous PageNext Page
You have been reading a chapter from
Instant GSON
Published in: Aug 2013Publisher: PacktISBN-13: 9781783282036
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Sandeep Patel

http://www.packtpub.com/developing-responsive-web-applications-with-ajax-and-jquery/book
Read more about Sandeep Patel