Class JsonOutput

java.lang.Object
org.openqa.selenium.json.JsonOutput
All Implemented Interfaces:
Closeable, AutoCloseable

public class JsonOutput extends Object implements Closeable
The JsonOutput class defines the operations used to serialize Java objects into JSON strings.
  • Method Details

    • setPrettyPrint

      public JsonOutput setPrettyPrint(boolean enablePrettyPrinting)
      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

      public JsonOutput 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.
      Parameters:
      writeClassName - Whether to include the "class" property (default: true)
      Returns:
      this JsonOutput object
    • beginObject

      public JsonOutput beginObject()
      Begin a new JSON object.
      Returns:
      this JsonOutput object
    • name

      public JsonOutput name(String 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 a JsonOutput.JsonObject
      NoSuchElementException - if serialization object stack is empty
    • endObject

      public JsonOutput endObject()
      End the current JSON object.
      Returns:
      this JsonOutput object
      Throws:
      JsonException - if top item on serialization object stack isn't a JsonOutput.JsonObject
      NoSuchElementException - if serialization object stack is empty
    • beginArray

      public JsonOutput beginArray()
      Begin a new JSON array.
      Returns:
      this JsonOutput object
    • endArray

      public JsonOutput endArray()
      End the current JSON array.
      Returns:
      this JsonOutput object
      Throws:
      JsonException - if top item on serialization object stack isn't a JsonOutput.JsonCollection
      NoSuchElementException - if serialization object stack is empty
    • write

      public JsonOutput write(Object value)
      Serialize the specified Java object as a JSON value.
      NOTE: This method limits traversal of nested objects to the default maximum depth.
      Parameters:
      value - Java object to serialize
      Returns:
      this JsonOutput object
      Throws:
      JsonException - if allowed depth has been reached
    • write

      public JsonOutput write(Object value, int maxDepth)
      Serialize the specified Java object as a JSON value.
      Parameters:
      value - Java object to serialize
      maxDepth - 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 interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      JsonException - if JSON stream isn't empty or an I/O exception is encountered
      NoSuchElementException - if serialization object stack is empty