Class DefaultJsonReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
JsonReader
implementation.-
Method Summary
Modifier and TypeMethodDescriptionReads and returns the current JSON structure theJsonReader
is pointing to.void
close()
Gets theJsonToken
that the reader currently points.static JsonReader
fromBytes
(byte[] json) Constructs an instance ofDefaultJsonReader
from abyte[]
.static JsonReader
fromStream
(InputStream json) Constructs an instance ofDefaultJsonReader
from anInputStream
.static JsonReader
fromString
(String json) Constructs an instance ofDefaultJsonReader
from a String.byte[]
Gets the binary value if the reader is currently pointing to aJsonToken.STRING
token.boolean
Gets the boolean value if the reader is currently pointing to aJsonToken.BOOLEAN
token.double
Gets the double value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.Gets the field name if the reader is currently pointing to aJsonToken.FIELD_NAME
.float
Gets the float value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.int
Gets the int value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.long
Gets the long value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.Gets the String value if the reader is currently pointing to aJsonToken.BOOLEAN
,JsonToken.NULL
,JsonToken.NUMBER
, orJsonToken.STRING
.Iterates to and returns the nextJsonToken
in the JSON encoded value.reset()
Creates a newJsonReader
reset to the beginning of the JSON stream.boolean
Indicates whether theJsonReader
supportsresetting
.void
Recursively skips the JSON token sub-stream if the current token is eitherJsonToken.START_ARRAY
orJsonToken.START_OBJECT
.Methods inherited from class com.azure.json.JsonReader
getBooleanNullableValue, getDoubleNullableValue, getFloatNullableValue, getIntegerNullableValue, getLongNullableValue, getNullableValue, getTextValue, isEndArrayOrObject, isStartArrayOrObject, readArray, readChildren, readChildren, readMap, readObject, readUntyped
-
Method Details
-
fromBytes
Constructs an instance ofDefaultJsonReader
from abyte[]
.- Parameters:
json
- JSONbyte[]
.- Returns:
- An instance of
DefaultJsonReader
. - Throws:
UncheckedIOException
- If aDefaultJsonReader
wasn't able to be constructed from the JSONbyte[]
.
-
fromString
Constructs an instance ofDefaultJsonReader
from a String.- Parameters:
json
- JSON String.- Returns:
- An instance of
DefaultJsonReader
. - Throws:
UncheckedIOException
- If aDefaultJsonReader
wasn't able to be constructed from the JSON String.
-
fromStream
Constructs an instance ofDefaultJsonReader
from anInputStream
.- Parameters:
json
- JSONInputStream
.- Returns:
- An instance of
DefaultJsonReader
. - Throws:
UncheckedIOException
- If aDefaultJsonReader
wasn't able to be constructed from the JSONInputStream
.
-
currentToken
Description copied from class:JsonReader
Gets theJsonToken
that the reader currently points.Returns null if the reader isn't pointing to a token. This happens if the reader hasn't begun to read the JSON value or if reading of the JSON value has completed.
- Specified by:
currentToken
in classJsonReader
- Returns:
- The
JsonToken
that the reader currently points, or null if the reader isn't pointing to a token.
-
nextToken
Description copied from class:JsonReader
Iterates to and returns the nextJsonToken
in the JSON encoded value.Returns null if iterating to the next token completes reading of the JSON encoded value.
- Specified by:
nextToken
in classJsonReader
- Returns:
- The next
JsonToken
in the JSON encoded value, or null if reading completes.
-
getBinaryValue
public byte[] getBinaryValue()Description copied from class:JsonReader
Gets the binary value if the reader is currently pointing to aJsonToken.STRING
token.This returns the equivalent of
Base64.getDecoder()
Base64.Decoder.decode(String)
.If the reader is pointing to a
JsonToken.NULL
null will be returned. If the reader is pointing to any other token type anIllegalStateException
will be thrown.- Specified by:
getBinaryValue
in classJsonReader
- Returns:
- The binary value based on whether the current token is
JsonToken.STRING
orJsonToken.NULL
.
-
getBooleanValue
public boolean getBooleanValue()Description copied from class:JsonReader
Gets the boolean value if the reader is currently pointing to aJsonToken.BOOLEAN
token.If the reader is pointing to any other token type an
IllegalStateException
will be thrown.If
Boolean
should be read useJsonReader.getBooleanNullableValue()
.- Specified by:
getBooleanValue
in classJsonReader
- Returns:
- The boolean value based on the
JsonToken.BOOLEAN
.
-
getDoubleValue
public double getDoubleValue()Description copied from class:JsonReader
Gets the double value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.JsonToken.STRING
will throw aNumberFormatException
if the underlying string value cannot be converted to a double.All other
JsonToken
types will throw anIllegalStateException
.If
Double
should be read useJsonReader.getDoubleNullableValue()
.- Specified by:
getDoubleValue
in classJsonReader
- Returns:
- The double value based on the current token.
-
getFloatValue
public float getFloatValue()Description copied from class:JsonReader
Gets the float value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.JsonToken.STRING
will throw aNumberFormatException
if the underlying string value cannot be converted to a float.All other
JsonToken
types will throw anIllegalStateException
.If
Float
should be read useJsonReader.getFloatNullableValue()
.- Specified by:
getFloatValue
in classJsonReader
- Returns:
- The float value based on the current token.
-
getIntValue
public int getIntValue()Description copied from class:JsonReader
Gets the int value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.JsonToken.STRING
will throw aNumberFormatException
if the underlying string value cannot be converted to an int.All other
JsonToken
types will throw anIllegalStateException
.If
Integer
should be read useJsonReader.getIntegerNullableValue()
- Specified by:
getIntValue
in classJsonReader
- Returns:
- The int value based on the current token.
-
getLongValue
public long getLongValue()Description copied from class:JsonReader
Gets the long value if the reader is currently pointing to aJsonToken.NUMBER
orJsonToken.STRING
.JsonToken.STRING
will throw aNumberFormatException
if the underlying string value cannot be converted to a long.All other
JsonToken
types will throw anIllegalStateException
.If
Long
should be read useJsonReader.getLongNullableValue()
.- Specified by:
getLongValue
in classJsonReader
- Returns:
- The long value based on the current token.
-
getStringValue
Description copied from class:JsonReader
Gets the String value if the reader is currently pointing to aJsonToken.BOOLEAN
,JsonToken.NULL
,JsonToken.NUMBER
, orJsonToken.STRING
.If the current token is a
JsonToken.BOOLEAN
, orJsonToken.NUMBER
the String representation of the value will be returned. If the current token isJsonToken.NULL
null will be returned.All other
JsonToken
types will throw anIllegalStateException
.- Specified by:
getStringValue
in classJsonReader
- Returns:
- The String value based on the current token.
-
getFieldName
Description copied from class:JsonReader
Gets the field name if the reader is currently pointing to aJsonToken.FIELD_NAME
.All other
JsonToken
types will throw anIllegalStateException
.- Specified by:
getFieldName
in classJsonReader
- Returns:
- The field name based on the current token.
-
skipChildren
public void skipChildren()Description copied from class:JsonReader
Recursively skips the JSON token sub-stream if the current token is eitherJsonToken.START_ARRAY
orJsonToken.START_OBJECT
.If the current token isn't the beginning of an array or object this method is a no-op.
- Specified by:
skipChildren
in classJsonReader
-
bufferObject
Description copied from class:JsonReader
Reads and returns the current JSON structure theJsonReader
is pointing to. This will mutate the current location of thisJsonReader
.If the
JsonReader.currentToken()
isn'tJsonToken.START_OBJECT
orJsonToken.FIELD_NAME
anIllegalStateException
will be thrown.The returned
JsonReader
is able to beJsonReader.reset()
to replay the underlying JSON stream.- Specified by:
bufferObject
in classJsonReader
- Returns:
- The buffered JSON object the
JsonReader
was pointing to.
-
resetSupported
public boolean resetSupported()Description copied from class:JsonReader
Indicates whether theJsonReader
supportsresetting
.- Specified by:
resetSupported
in classJsonReader
- Returns:
- Whether
JsonReader.reset()
is supported.
-
reset
Description copied from class:JsonReader
Creates a newJsonReader
reset to the beginning of the JSON stream.Use
JsonReader.resetSupported()
to determine whether theJsonReader
can be reset. If resetting is called and it isn't supported anIllegalStateException
will be thrown.- Specified by:
reset
in classJsonReader
- Returns:
- A new
JsonReader
reset to the beginning of the JSON stream.
-
close
- Throws:
IOException
-