JSON value types

javax.json.JsonValue is a top-level interface used to represent the node value types of JSON data, as shown ahead:

At runtime, it takes one of the following forms on the basis of the content type:

  • javax.json.JsonObject: This form is an immutable JSON object value
  • javax.json.JsonArray: This form is an immutable array representing an ordered sequence of zero or more JSON values
  • javax.json.JsonNumber: This form is an immutable JSON numerical value
  • javax.json.JsonString: This form is an immutable JSON string value
  • javax.json.JsonValue.TRUE: This form represents the JSON TRUE value
  • javax.json.JsonValue.FALSE: This form represents the JSON FALSE value
  • javax.json.JsonValue.NULL: This form represents the JSON NULL value

By now, we have read the entire JSON content from the input file into the Employee objects. It is now time for some cleanup activities. The following code closes the inputStream and jsonReader objects after use. This lets the runtime release the system resources associated with the stream:

try(InputStream inputStream = getClass().getResourceAsStream(jsonFileName);
Reader reader = new InputStreamReader(inputStream, "UTF-8");
JsonReader jsonReader = Json.createReader(reader))
Once you have finished using the inputStream, outputStream, JsonReader, or JSonWriter objects, make sure that you close them to release the associated resources. 

The try-with-resources available from Java 1.7 is used to release resources automatically once the application stops. This is applicable only when the resource implements the java.lang.AutoCloseable interface.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.157