Gson
Gson
Main page

Gson

logo
Community Hub0 subscribers

Gson

logo
Community Hub0 subscribers
What are your thoughts?
Be the first to start a discussion here.
Be the first to start a discussion here.
Gson

Gson, or Google Gson, is an open-source Java library that serializes Java objects to JSON (and deserializes them back to Java).

The Gson library was originally developed for internal purposes at Google, with Version 1.0 released on May 22, 2008, under the terms of the Apache License 2.0.

Gson utilizes reflection, meaning that classes do not have to be modified to be serialized or deserialized. By default, a class only needs a defined default (no-args) constructor; however, this requirement can be circumvented (see Features).

The following example demonstrates the basic usage of Gson when serializing a sample object:

Calling the code of the above Main class will result in the following JSON output:

Since the Person's field age is marked as transient, it is not included in the output.

To deserialize the output produced by the last example, you can execute the code above, which generates the following output:

This shows how Gson can be used with the Java Platform Module System for the example above:

See all
User Avatar
No comments yet.