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

Writing JSON data with Gson streaming APIs

You can use com.google.gson.stream.JsonWriter to write the JSON-encoded value to the stream. The following example demonstrates the use of Gson streaming APIs for writing JSON data. This example writes the JSON array representation of employee objects to the emp-array.json file. The steps are as follows:

  1. To write the JSON content, build the JsonWriter object, which takes the implementation of java.io.Writer as the input.
  2. Once the JsonWriter instance is created, start writing the JSON content. As this example writes an array of the employee objects, we start by invoking the beginArray() method. This call begins encoding a new array. Then, call beginObject() to start encoding a new object. This is ...
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