Skip to Content
RESTful Java Web Services - Third Edition
book

RESTful Java Web Services - Third Edition

by Balachandar Bogunuva Mohanram
November 2017
Intermediate to advanced
420 pages
10h 29m
English
Packt Publishing
Content preview from RESTful Java Web Services - Third Edition

Reading JSON data with Gson streaming APIs

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:

  1. 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.
  2. 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

RESTful Java Web Services, Second Edition

RESTful Java Web Services, Second Edition

Jobinesh Purushothaman
Java Web Services

Java Web Services

David A Chappell, Tyler Jewell

Publisher Resources

ISBN: 9781788294041Supplemental Content