Package org.openqa.selenium.json
Class JsonInput
java.lang.Object
org.openqa.selenium.json.JsonInput
- All Implemented Interfaces:
Closeable
,AutoCloseable
The JsonInput class defines the operations used to deserialize JSON strings into Java
objects.
-
Method Summary
Modifier and TypeMethodDescriptionaddCoercers
(Iterable<TypeCoercer<?>> coercers) Add the specified type coercers to the set installed in the JSON coercion manager.addCoercers
(TypeCoercer<?>... coercers) Add the specified type coercers to the set installed in the JSON coercion manager.void
Process the opening square bracket of a JSON array.void
Process the opening curly brace of a JSON object.void
close()
void
endArray()
Process the closing square bracket of a JSON array.void
Process the closing curly brace of a JSON object.boolean
hasNext()
Determine whether an element is pending for the current container from the JSON input stream.boolean
Read the next element of the JSON input stream as a boolean value.Read the next element of the JSON input stream as an instant.nextName()
Read the next element of the JSON input stream as an object property name.nextNull()
Read the next element of the JSON input stream as anull
object.Read the next element of the JSON input stream as a number.Read the next element of the JSON input stream as a string.peek()
Peek at the next input string character to determine the pending JSON element type.propertySetting
(PropertySetting setter) Change how property setting is done.<T> T
Read the next element from the JSON input stream as the specified type.<T> List<T>
Read an array of elements from the JSON input stream with elements as the specified type.void
Discard the pending JSON property value.
-
Method Details
-
propertySetting
Change how property setting is done. It's polite to set the value back once done processing.- Parameters:
setter
- The newPropertySetting
to use.- Returns:
- The previous
PropertySetting
that has just been replaced.
-
addCoercers
Add the specified type coercers to the set installed in the JSON coercion manager.- Parameters:
coercers
- array of zero or moreTypeCoercer
objects- Returns:
- this
JsonInput
object with added type coercers - Throws:
JsonException
- if thisJsonInput
has already begun processing its input
-
addCoercers
Add the specified type coercers to the set installed in the JSON coercion manager.- Parameters:
coercers
- iterable collection ofTypeCoercer
objects- Returns:
- this
JsonInput
object with added type coercers - Throws:
JsonException
- if thisJsonInput
has already begun processing its input
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
UncheckedIOException
- if an I/O exception is encountered
-
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 elementUncheckedIOException
- 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
orfalse
- Throws:
JsonException
- if the next element isn't the expected booleanUncheckedIOException
- if an I/O exception is encountered
-
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 colonUncheckedIOException
- if an I/O exception is encountered
-
nextNull
Read the next element of the JSON input stream as anull
object.- Returns:
null
object- Throws:
JsonException
- if the next element isn't anull
UncheckedIOException
- if an I/O exception is encountered
-
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 numberUncheckedIOException
- if an I/O exception is encountered
-
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 stringUncheckedIOException
- if an I/O exception is encountered
-
nextInstant
Read the next element of the JSON input stream as an instant.- Returns:
Instant
object- Throws:
JsonException
- if the next element isn't aLong
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; otherwisefalse
- Throws:
JsonException
- if no container is openUncheckedIOException
- 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 typeUncheckedIOException
- if an I/O exception is encountered
-
read
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 orTypeToken
)- Returns:
- object of the specified type deserialized from the JSON input stream
NOTE: Returnsnull
if the input string is exhausted. - Throws:
JsonException
- if coercion of the next element to the specified type failsUncheckedIOException
- if an I/O exception is encountered
-
readArray
Read an array of elements from the JSON input stream with elements as the specified type.- Type Parameters:
T
- result type of the item in the list (as specified by [type])- Parameters:
type
- data type for deserialization (class orTypeToken
)- Returns:
- list of objects of the specified type deserialized from the JSON input stream
NOTE: Returnsnull
if the input string is exhausted. - Throws:
JsonException
- if coercion of the next element to the specified type failsUncheckedIOException
- if an I/O exception is encountered
-