The following example demonstrates the use of the Gson streaming APIs for reading JSON data.
This example converts the JSON array of employee objects present in the emp-array.json file into a list of Employee objects. The steps are as follows:
- Gson provides com.google.gson.stream.JsonReader to read the JSON encoded value as a stream of tokens. You can create a JsonReader instance by supplying the InputStreamReader instance as input.
- As the next step, start parsing the contents. The tokens returned by JsonReader are traversed in the same order as they appear in the JSON document. As this example uses an array of JSON objects as input, the parser starts off by calling beginArray(). This call consumes ...