Package org.openqa.selenium.json
Class JsonOutput
java.lang.Object
org.openqa.selenium.json.JsonOutput
- All Implemented Interfaces:
Closeable,AutoCloseable
The JsonOutput class defines the operations used to serialize Java objects into JSON
strings.
-
Method Summary
Modifier and TypeMethodDescriptionBegin a new JSON array.Begin a new JSON object.voidclose()endArray()End the current JSON array.End the current JSON object.Set the name of a new JSON object property.setPrettyPrint(boolean enablePrettyPrinting) Specify whether the serialized JSON object should be formatted with line breaks and indentation ("pretty printed").Serialize the specified Java object as a JSON value.
NOTE: This method limits traversal of nested objects to the defaultmaximum depth.Serialize the specified Java object as a JSON value.writeClassName(boolean writeClassName) Specify whether the serialized JSON object should include a "class" property whose value is the fully-qualified class name of the Java object being serialized.
-
Method Details
-
setPrettyPrint
Specify whether the serialized JSON object should be formatted with line breaks and indentation ("pretty printed").- Parameters:
enablePrettyPrinting-falsefor compact format;truefor "pretty printing" (default:true)- Returns:
- this
JsonOutputobject
-
writeClassName
Specify whether the serialized JSON object should include a "class" property whose value is the fully-qualified class name of the Java object being serialized.- Parameters:
writeClassName- Whether to include the "class" property (default:true)- Returns:
- this
JsonOutputobject
-
beginObject
Begin a new JSON object.- Returns:
- this
JsonOutputobject
-
name
Set the name of a new JSON object property.- Parameters:
name- JSON object property name- Returns:
- this
JsonOutputobject - Throws:
JsonException- if top item on serialization object stack isn't aJsonOutput.JsonObjectNoSuchElementException- if serialization object stack is empty
-
endObject
End the current JSON object.- Returns:
- this
JsonOutputobject - Throws:
JsonException- if top item on serialization object stack isn't aJsonOutput.JsonObjectNoSuchElementException- if serialization object stack is empty
-
beginArray
Begin a new JSON array.- Returns:
- this
JsonOutputobject
-
endArray
End the current JSON array.- Returns:
- this
JsonOutputobject - Throws:
JsonException- if top item on serialization object stack isn't aJsonOutput.JsonCollectionNoSuchElementException- if serialization object stack is empty
-
write
Serialize the specified Java object as a JSON value.
NOTE: This method limits traversal of nested objects to the defaultmaximum depth.- Parameters:
value- Java object to serialize- Returns:
- this
JsonOutputobject - Throws:
JsonException- if allowed depth has been reached
-
write
Serialize the specified Java object as a JSON value.- Parameters:
value- Java object to serializemaxDepth- maximum depth of nested object traversal- Returns:
- this
JsonOutputobject - Throws:
JsonException- if allowed depth has been reached
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
JsonException- if JSON stream isn't empty or an I/O exception is encounteredNoSuchElementException- if serialization object stack is empty
-