Class GsonJsonReader
- All Implemented Interfaces:
Closeable,AutoCloseable
JsonReader-
Method Summary
Modifier and TypeMethodDescriptionReads and returns the current JSON structure theJsonReaderis pointing to.voidclose()Gets theJsonTokenthat the reader currently points.static JsonReaderfromBytes(byte[] json) Constructs an instance ofGsonJsonReaderfrom abyte[].static JsonReaderfromStream(InputStream json) Constructs an instance ofGsonJsonReaderfrom anInputStream.static JsonReaderfromString(String json) Constructs an instance ofGsonJsonReaderfrom a String.byte[]Gets the binary value if the reader is currently pointing to aJsonToken.STRINGtoken.booleanGets the boolean value if the reader is currently pointing to aJsonToken.BOOLEANtoken.doubleGets the double value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.Gets the field name if the reader is currently pointing to aJsonToken.FIELD_NAME.floatGets the float value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.intGets the int value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.longGets the long value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.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 nextJsonTokenin the JSON encoded value.reset()Creates a newJsonReaderreset to the beginning of the JSON stream.booleanIndicates whether theJsonReadersupportsresetting.voidRecursively skips the JSON token sub-stream if the current token is eitherJsonToken.START_ARRAYorJsonToken.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 ofGsonJsonReaderfrom abyte[].- Parameters:
json- JSONbyte[].- Returns:
- An instance of
GsonJsonReader.
-
fromString
Constructs an instance ofGsonJsonReaderfrom a String.- Parameters:
json- JSON String.- Returns:
- An instance of
GsonJsonReader.
-
fromStream
Constructs an instance ofGsonJsonReaderfrom anInputStream.- Parameters:
json- JSONInputStream.- Returns:
- An instance of
GsonJsonReader.
-
currentToken
Description copied from class:JsonReaderGets theJsonTokenthat 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:
currentTokenin classJsonReader- Returns:
- The
JsonTokenthat the reader currently points, or null if the reader isn't pointing to a token.
-
nextToken
Description copied from class:JsonReaderIterates to and returns the nextJsonTokenin the JSON encoded value.Returns null if iterating to the next token completes reading of the JSON encoded value.
- Specified by:
nextTokenin classJsonReader- Returns:
- The next
JsonTokenin the JSON encoded value, or null if reading completes.
-
getBinaryValue
public byte[] getBinaryValue()Description copied from class:JsonReaderGets the binary value if the reader is currently pointing to aJsonToken.STRINGtoken.This returns the equivalent of
Base64.getDecoder()Base64.Decoder.decode(String).If the reader is pointing to a
JsonToken.NULLnull will be returned. If the reader is pointing to any other token type anIllegalStateExceptionwill be thrown.- Specified by:
getBinaryValuein classJsonReader- Returns:
- The binary value based on whether the current token is
JsonToken.STRINGorJsonToken.NULL.
-
getBooleanValue
public boolean getBooleanValue()Description copied from class:JsonReaderGets the boolean value if the reader is currently pointing to aJsonToken.BOOLEANtoken.If the reader is pointing to any other token type an
IllegalStateExceptionwill be thrown.If
Booleanshould be read useJsonReader.getBooleanNullableValue().- Specified by:
getBooleanValuein classJsonReader- Returns:
- The boolean value based on the
JsonToken.BOOLEAN.
-
getDoubleValue
public double getDoubleValue()Description copied from class:JsonReaderGets the double value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.JsonToken.STRINGwill throw aNumberFormatExceptionif the underlying string value cannot be converted to a double.All other
JsonTokentypes will throw anIllegalStateException.If
Doubleshould be read useJsonReader.getDoubleNullableValue().- Specified by:
getDoubleValuein classJsonReader- Returns:
- The double value based on the current token.
-
getFloatValue
public float getFloatValue()Description copied from class:JsonReaderGets the float value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.JsonToken.STRINGwill throw aNumberFormatExceptionif the underlying string value cannot be converted to a float.All other
JsonTokentypes will throw anIllegalStateException.If
Floatshould be read useJsonReader.getFloatNullableValue().- Specified by:
getFloatValuein classJsonReader- Returns:
- The float value based on the current token.
-
getIntValue
public int getIntValue()Description copied from class:JsonReaderGets the int value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.JsonToken.STRINGwill throw aNumberFormatExceptionif the underlying string value cannot be converted to an int.All other
JsonTokentypes will throw anIllegalStateException.If
Integershould be read useJsonReader.getIntegerNullableValue()- Specified by:
getIntValuein classJsonReader- Returns:
- The int value based on the current token.
-
getLongValue
public long getLongValue()Description copied from class:JsonReaderGets the long value if the reader is currently pointing to aJsonToken.NUMBERorJsonToken.STRING.JsonToken.STRINGwill throw aNumberFormatExceptionif the underlying string value cannot be converted to a long.All other
JsonTokentypes will throw anIllegalStateException.If
Longshould be read useJsonReader.getLongNullableValue().- Specified by:
getLongValuein classJsonReader- Returns:
- The long value based on the current token.
-
getStringValue
Description copied from class:JsonReaderGets 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.NUMBERthe String representation of the value will be returned. If the current token isJsonToken.NULLnull will be returned.All other
JsonTokentypes will throw anIllegalStateException.- Specified by:
getStringValuein classJsonReader- Returns:
- The String value based on the current token.
-
getFieldName
Description copied from class:JsonReaderGets the field name if the reader is currently pointing to aJsonToken.FIELD_NAME.All other
JsonTokentypes will throw anIllegalStateException.- Specified by:
getFieldNamein classJsonReader- Returns:
- The field name based on the current token.
-
skipChildren
public void skipChildren()Description copied from class:JsonReaderRecursively skips the JSON token sub-stream if the current token is eitherJsonToken.START_ARRAYorJsonToken.START_OBJECT.If the current token isn't the beginning of an array or object this method is a no-op.
- Specified by:
skipChildrenin classJsonReader
-
bufferObject
Description copied from class:JsonReaderReads and returns the current JSON structure theJsonReaderis pointing to. This will mutate the current location of thisJsonReader.If the
JsonReader.currentToken()isn'tJsonToken.START_OBJECTorJsonToken.FIELD_NAMEanIllegalStateExceptionwill be thrown.The returned
JsonReaderis able to beJsonReader.reset()to replay the underlying JSON stream.- Specified by:
bufferObjectin classJsonReader- Returns:
- The buffered JSON object the
JsonReaderwas pointing to.
-
resetSupported
public boolean resetSupported()Description copied from class:JsonReaderIndicates whether theJsonReadersupportsresetting.- Specified by:
resetSupportedin classJsonReader- Returns:
- Whether
JsonReader.reset()is supported.
-
reset
Description copied from class:JsonReaderCreates a newJsonReaderreset to the beginning of the JSON stream.Use
JsonReader.resetSupported()to determine whether theJsonReadercan be reset. If resetting is called and it isn't supported anIllegalStateExceptionwill be thrown.- Specified by:
resetin classJsonReader- Returns:
- A new
JsonReaderreset to the beginning of the JSON stream.
-
close
- Throws:
IOException
-