Skip to content

Gson fromJson Method Example

Gson fromJson method example shows how to use the fromJson method of the Gson class to convert string to JSON object in Java.

The fromJson method of the Gson class is used to parse the string data into the specified class.

The first argument to the fromJson method is the string containing JSON data, and the second argument is the class. Here is an example that converts a string to a generic JsonObject using the Gson library.

Output

The above example uses the fromJson method to convert the string to a generic JsonObject.

We can also use the same method to convert data to a pojo class as given below.

Output

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.