Class JsonInput
java.lang.Object
org.openqa.selenium.json.JsonInput
- All Implemented Interfaces:
Closeable, AutoCloseable
-
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.voidProcess the opening square bracket of a JSON array.voidProcess the opening curly brace of a JSON object.voidclose()voidendArray()Process the closing square bracket of a JSON array.voidProcess the closing curly brace of a JSON object.booleanhasNext()Determine whether an element is pending for the current container from the JSON input stream.booleanRead the next element of the JSON input stream as a boolean value.voidnextEnd()Read the next element of the JSON input stream and expect the end of the input.Reads the next JSON number token as an exactBigDecimal, preserving the fractional and range information thatnextNumber()'sdouble-valued decimal/exponent path loses (a JSON integer beyonddouble's 53-bit mantissa, or a decimal/exponent lexeme that happens to be a whole number, both go through thatdoubleconversion — see its own fast-path comment).@Nullable InstantDeprecated, for removal: This API element is subject to removal in a future version.nextName()Read the next element of the JSON input stream as an object property name.@Nullable ObjectnextNull()Read the next element of the JSON input stream as anullobject.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> @Nullable TRead 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.readMap()<T> TreadMapElement(String key) <T> TreadNonNull(Type type) voidDiscard 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 newPropertySettingto use.- Returns:
- The previous
PropertySettingthat 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 moreTypeCoercerobjects- Returns:
- this
JsonInputobject with added type coercers - Throws:
JsonException- if thisJsonInputhas already begun processing its input
-
addCoercers
Add the specified type coercers to the set installed in the JSON coercion manager.- Parameters:
coercers- iterable collection ofTypeCoercerobjects- Returns:
- this
JsonInputobject with added type coercers - Throws:
JsonException- if thisJsonInputhas already begun processing its input
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein 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:
JsonTypeindicating 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:
trueorfalse- 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 anullobject.- Returns:
nullobject- Throws:
JsonException- if the next element isn't anullUncheckedIOException- if an I/O exception is encountered
-
nextNumber
Read the next element of the JSON input stream as a number.- Returns:
Numberobject- Throws:
JsonException- if the next element isn't a numberUncheckedIOException- if an I/O exception is encountered
-
nextExactNumber
Reads the next JSON number token as an exactBigDecimal, preserving the fractional and range information thatnextNumber()'sdouble-valued decimal/exponent path loses (a JSON integer beyonddouble's 53-bit mantissa, or a decimal/exponent lexeme that happens to be a whole number, both go through thatdoubleconversion — see its own fast-path comment). Consumes the number from the stream exactly likenextNumber(); the two are not meant to be called on the same token.- Returns:
- the number's exact value as a
BigDecimal - Throws:
JsonException- if the next element isn't a number, or is a syntactically valid JSON numberBigDecimalstill can't represent (RFC 8259 places no bound on an exponent's magnitude;BigDecimal's scale is a 32-bitint, so an exponent with enough digits overflows it)UncheckedIOException- if an I/O exception is encountered
-
nextString
Read the next element of the JSON input stream as a string.- Returns:
Stringobject- Throws:
JsonException- if the next element isn't a stringUncheckedIOException- if an I/O exception is encountered
-
nextInstant
Deprecated, for removal: This API element is subject to removal in a future version.Instant is not a basic JSON type, use theInstantCoercerinstead.Read the next element of the JSON input stream as an instant.- Returns:
Instantobject- Throws:
JsonException- if the next element isn't aLongUncheckedIOException- if an I/O exception is encountered
-
nextEnd
public void nextEnd()Read the next element of the JSON input stream and expect the end of the input.- Throws:
JsonException- if the next element isn't the end of the input
-
hasNext
public boolean hasNext()Determine whether an element is pending for the current container from the JSON input stream.- Returns:
trueif 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: Returnsnullif 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
-
readNonNull
-
readMap
-
readMapElement
-
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: Returnsnullif 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
-
InstantCoercerinstead.