- Instant GSON
- Sandeep Kumar Patel
- 685字
- 2021-04-02 10:33:59
So, what is GSON?
In this section, we will cover the JSON data exchange format and its significance, and give an introduction to the GSON library. Finally, we will look up the GSON library and its top features.
This chapter distills the theory of data exchange format from the main core. No previous knowledge about the subject is necessary, but I assume that you are familiar with the fundamentals of JavaScript.
The data exchange format is a very vital area of information technology. Data is read and consumed by many heterogeneous applications to form information. The heterogeneous nature means these applications take the input data in their proprietary format. This requires the input data to be preformatted before it is consumed by the main application, which adds an additional level of complexity to an application. To address this need, a common data exchange format is put in place for communication. This has led to the origin of many popular standard formats such as XML, YAML, and JSON.
Java Script Object Notation (JSON) originates from the most rocking JavaScript language. JSON has derived its syntax from JavaScript objects. In JavaScript, an object can be created by using the new
keyword or anonymously. An anonymous JavaScript object can be created using curly braces with or without a key/value pair.
A typical anonymous JavaScript object syntax is as follows:
{}, {key: value}, {key1: value1, key2: value2}…
In the JavaScript language, almost everything is treated as an object, starting from a function to an array. A typical anonymous array in JavaScript can follow one of the following syntaxes:
[],[{}],[{key: value}],[{key1: value1},{key2: value2}...
Let's test it:
VarnumberArray = [10,20,30,40]; console.log (typeofnumberArray);
The output of the preceding code is an object.
In the Firebug console, it would look as follows:

In the preceding code, a JavaScript array is defined with numbers as elements. In the second line, we are printing its type on the console. It displays the object text in the Console. From the output, it is evident that arrays in JavaScript are objects.
A Web 2.0-based client and server application exchanges data in AJAX mode. XML and JSON are the most preferred data formats in web application development. JSON is the most preferred for the data interchange format because of its following features:
- Lightweight in footprints: The size of a JSON response or file is much smaller than that of an XML one.
- Native nature: All browsers have JavaScript as their native language and JSON follows the same object concept of JavaScript, which makes its rendering faster.
- Simpler syntax: JSON has simpler syntaxes to represent data comprising curly braces and the key/value pairs separated by a colon. This makes the job of parsing easier.
GSON is an open source application programming interface project written in the Java language for handling the JSON data format. It converts a Java object into its JSON representation. It can also be used to convert a JSON string into an equivalent Java object.

The root gson
package contains all the common classes and interfaces for JSON data handling. The subpackages inside gson
are reflect
, annotation
, and stream
. The reflect
package holds the classes and interfaces that deal with information on the Java generic types. The annotation
package contains the related classes and interfaces for custom name mapping for object properties. The stream
package contains the classes and interfaces that are related to reading and writing to and from a stream.
Initial goals of the GSON designs are as follows:
- To have a simple conversion mechanism for converting a Java object to and from JSON. The GSON Java project has a large number of utility methods exposed as APIs for the developers to use.
- To allow pre-existing unmodifiable Java objects to be converted to and from JSON.
- To customize the representation of objects. GSON provides custom mapping of names for the object fields while serializing it to a JSON string.
- To provide a compact and formatted output. By default, the generated JSON string for a Java object is in a compact form. GSON provides pretty printing facilities to get it in the human-readable format.
- Sakai CLE Courseware Management
- Moodle 2.0 E/Learning Course Development
- iOS應用逆向與安全之道
- 設計模式之禪(第2版)
- Plone 3 Multimedia
- Final Cut Pro短視頻剪輯入門教程
- 零基礎學會聲會影2018(全視頻教學版)
- Moldflow 2021模流分析從入門到精通(升級版)
- ASP.NET 3.5 Social Networking
- Plone 3 Intranets
- Refactoring with Microsoft Visual Studio 2010
- Microsoft SQL Azure Enterprise Application Development
- Photoshop數字圖像處理
- 中文版Premiere Pro CS6視頻編輯(慕課版)
- Flash CS5動畫設計教程