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.void
close()
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 br formatted with line breaks and indention ("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 br formatted with line breaks and indention ("pretty printed").- Parameters:
enablePrettyPrinting
-false
for compact format;true
for "pretty printing" (default:true
)- Returns:
- this
JsonOutput
object
-
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
JsonOutput
object
-
beginObject
Begin a new JSON object.- Returns:
- this
JsonOutput
object
-
name
Set the name of a new JSON object property.- Parameters:
name
- JSON object property name- Returns:
- this
JsonOutput
object - Throws:
JsonException
- if top item on serialization object stack isn't aJsonOutput.JsonObject
NoSuchElementException
- if serialization object stack is empty
-
endObject
End the current JSON object.- Returns:
- this
JsonOutput
object - Throws:
JsonException
- if top item on serialization object stack isn't aJsonOutput.JsonObject
NoSuchElementException
- if serialization object stack is empty
-
beginArray
Begin a new JSON array.- Returns:
- this
JsonOutput
object
-
endArray
End the current JSON array.- Returns:
- this
JsonOutput
object - Throws:
JsonException
- if top item on serialization object stack isn't aJsonOutput.JsonCollection
NoSuchElementException
- 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
JsonOutput
object - 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
JsonOutput
object - Throws:
JsonException
- if allowed depth has been reached
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
JsonException
- if JSON stream isn't empty or an I/O exception is encounteredNoSuchElementException
- if serialization object stack is empty
-