Class JsonInput

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

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

    • propertySetting

      public PropertySetting propertySetting(PropertySetting setter)
      Change how property setting is done. It's polite to set the value back once done processing.
      Parameters:
      setter - The new PropertySetting to use.
      Returns:
      The previous PropertySetting that has just been replaced.
    • addCoercers

      public JsonInput addCoercers(TypeCoercer<?>... coercers)
      Add the specified type coercers to the set installed in the JSON coercion manager.
      Parameters:
      coercers - array of zero or more TypeCoercer objects
      Returns:
      this JsonInput object with added type coercers
      Throws:
      JsonException - if this JsonInput has already begun processing its input
    • addCoercers

      public JsonInput addCoercers(Iterable<TypeCoercer<?>> coercers)
      Add the specified type coercers to the set installed in the JSON coercion manager.
      Parameters:
      coercers - iterable collection of TypeCoercer objects
      Returns:
      this JsonInput object with added type coercers
      Throws:
      JsonException - if this JsonInput has already begun processing its input
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      UncheckedIOException - if an I/O exception is encountered
    • peek

      public JsonType peek()
      Peek at the next input string character to determine the pending JSON element type.
      Returns:
      JsonType indicating the pending JSON element type
      Throws:
      JsonException - if unable to determine the type of the pending element
      UncheckedIOException - if an I/O exception is encountered
    • nextBoolean

      public boolean nextBoolean()
      Read the next element of the JSON input stream as a boolean value.
      Returns:
      true or false
      Throws:
      JsonException - if the next element isn't the expected boolean
      UncheckedIOException - if an I/O exception is encountered
    • nextName

      public String nextName()
      Read the next element of the JSON input stream as an object property name.
      Returns:
      JSON object property name
      Throws:
      JsonException - if the next element isn't a string followed by a colon
      UncheckedIOException - if an I/O exception is encountered
    • nextNull

      public Object nextNull()
      Read the next element of the JSON input stream as a null object.
      Returns:
      null object
      Throws:
      JsonException - if the next element isn't a null
      UncheckedIOException - if an I/O exception is encountered
    • nextNumber

      public Number nextNumber()
      Read the next element of the JSON input stream as a number.
      Returns:
      Number object
      Throws:
      JsonException - if the next element isn't a number
      UncheckedIOException - if an I/O exception is encountered
    • nextString

      public String nextString()
      Read the next element of the JSON input stream as a string.
      Returns:
      String object
      Throws:
      JsonException - if the next element isn't a string
      UncheckedIOException - if an I/O exception is encountered
    • nextInstant

      public Instant nextInstant()
      Read the next element of the JSON input stream as an instant.
      Returns:
      Instant object
      Throws:
      JsonException - if the next element isn't a Long
      UncheckedIOException - if an I/O exception is encountered
    • hasNext

      public boolean hasNext()
      Determine whether an element is pending for the current container from the JSON input stream.
      Returns:
      true if an element is pending; otherwise false
      Throws:
      JsonException - if no container is open
      UncheckedIOException - if an I/O exception is encountered
    • beginArray

      public void beginArray()
      Process the opening square bracket of a JSON array.
      Throws:
      UncheckedIOException - if an I/O exception is encountered
    • endArray

      public void endArray()
      Process the closing square bracket of a JSON array.
      Throws:
      UncheckedIOException - if an I/O exception is encountered
    • beginObject

      public void beginObject()
      Process the opening curly brace of a JSON object.
      Throws:
      UncheckedIOException - if an I/O exception is encountered
    • endObject

      public void endObject()
      Process the closing curly brace of a JSON object.
      Throws:
      UncheckedIOException - if an I/O exception is encountered
    • skipValue

      public void skipValue()
      Discard the pending JSON property value.
      Throws:
      JsonException - if the pending element isn't a value type
      UncheckedIOException - if an I/O exception is encountered
    • read

      public <T> T read(Type type)
      Read the next element from the JSON input stream as the specified type.
      Type Parameters:
      T - result type (as specified by [type])
      Parameters:
      type - data type for deserialization (class or TypeToken)
      Returns:
      object of the specified type deserialized from the JSON input stream
      NOTE: Returns null if the input string is exhausted.
      Throws:
      JsonException - if coercion of the next element to the specified type fails
      UncheckedIOException - if an I/O exception is encountered