DEV Community

loizenai
loizenai

Posted on

Gson to convert Java Object to/from Json

https://grokonez.com/json/gson-converting-java-object-tofrom-json

Gson to convert Java Object to/from Json

The tutorial guides you how to convert Java Object to Json and vice-versa by Gson.

Related Articles:

A. Concepts

2 important concepts need introduce: json & gson

I. Json

  • JSON: JavaScript Object Notation.
  • A lightweight data-interchange format.
  • It is easy for machines to parse and generate.
  • JSON is a text format that is completely language independent Example:
    
    {"id":1,"firstname":"John","lastname":"Kennedy"}
    

II. Gson library

Gson is a Java library for converting Java Objects into their JSON. Provide 2 methods: toJson() and fromJson() methods to convert Java objects to JSON and vice-versa.

https://grokonez.com/json/gson-converting-java-object-tofrom-json

Gson to convert Java Object to/from Json

Top comments (0)