public abstract class JsonParser implements Closeable
Abstract low-level JSON parser. See https://developers.google.com/api-client-library/java/google-http-java-client/json
Implementation has no fields and therefore thread-safe, but sub-classes are not necessarily thread-safe.
If a JSON map is encountered while using a destination class of type Map, then an java.util.ArrayMap is used by default for the parsed values.
Implements
CloseableConstructors
JsonParser()
public JsonParser()
Methods
<T>parse(Class<T> destinationClass)
public final T <T>parse(Class<T> destinationClass)
Parse a JSON object, array, or value into a new instance of the given destination class.
If it parses an object, after this method ends, the current token will be the object's ending JsonToken#END_OBJECT. If it parses an array, after this method ends, the current token will be the array's ending JsonToken#END_ARRAY.
Parameter | |
---|---|
Name | Description |
destinationClass | Class<T> destination class that has a public default constructor to use to create a new instance |
Returns | |
---|---|
Type | Description |
T | new instance of the parsed destination class |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parse(Class<T> destinationClass, CustomizeJsonParser customizeParser)
public final T <T>parse(Class<T> destinationClass, CustomizeJsonParser customizeParser)
Beta
Parse a JSON object, array, or value into a new instance of the given destination class,
optionally using the given parser customizer.
If it parses an object, after this method ends, the current token will be the object's ending JsonToken#END_OBJECT. If it parses an array, after this method ends, the current token will be the array's ending JsonToken#END_ARRAY.
Parameters | |
---|---|
Name | Description |
destinationClass | Class<T> destination class that has a public default constructor to use to create a new instance |
customizeParser | CustomizeJsonParser optional parser customizer or |
Returns | |
---|---|
Type | Description |
T | new instance of the parsed destination class |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseAndClose(Class<T> destinationClass)
public final T <T>parseAndClose(Class<T> destinationClass)
Parse a JSON object, array, or value into a new instance of the given destination class, and then closes the parser.
Parameter | |
---|---|
Name | Description |
destinationClass | Class<T> destination class that has a public default constructor to use to create a new instance |
Returns | |
---|---|
Type | Description |
T | new instance of the parsed destination class |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseAndClose(Class<T> destinationClass, CustomizeJsonParser customizeParser)
public final T <T>parseAndClose(Class<T> destinationClass, CustomizeJsonParser customizeParser)
Beta
Parse a JSON object, array, or value into a new instance of the given destination class using
<xref uid="com.google.api.client.json.JsonParser.
Parameters | |
---|---|
Name | Description |
destinationClass | Class<T> destination class that has a public default constructor to use to create a new instance |
customizeParser | CustomizeJsonParser optional parser customizer or |
Returns | |
---|---|
Type | Description |
T | new instance of the parsed destination class |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArray(Class<?> destinationCollectionClass, Class<T> destinationItemClass)
public final Collection<T> <T>parseArray(Class<?> destinationCollectionClass, Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser into the given destination collection.
Parameters | |
---|---|
Name | Description |
destinationCollectionClass | Class<?> class of destination collection (must have a public default constructor) |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
Returns | |
---|---|
Type | Description |
Collection<T> |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArray(Class<?> destinationCollectionClass, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
public final Collection<T> <T>parseArray(Class<?> destinationCollectionClass, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
Beta
Parse a JSON Array from the given JSON parser into the given destination collection, optionally
using the given parser customizer.
Parameters | |
---|---|
Name | Description |
destinationCollectionClass | Class<?> class of destination collection (must have a public default constructor) |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
customizeParser | CustomizeJsonParser optional parser customizer or |
Returns | |
---|---|
Type | Description |
Collection<T> |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArray(Collection<? super T> destinationCollection, Class<T> destinationItemClass)
public final void <T>parseArray(Collection<? super T> destinationCollection, Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser into the given destination collection.
Parameters | |
---|---|
Name | Description |
destinationCollection | Collection<? super T> destination collection |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArray(Collection<? super T> destinationCollection, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
public final void <T>parseArray(Collection<? super T> destinationCollection, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
Beta
Parse a JSON Array from the given JSON parser into the given destination collection, optionally
using the given parser customizer.
Parameters | |
---|---|
Name | Description |
destinationCollection | Collection<? super T> destination collection |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
customizeParser | CustomizeJsonParser optional parser customizer or |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArrayAndClose(Class<?> destinationCollectionClass, Class<T> destinationItemClass)
public final Collection<T> <T>parseArrayAndClose(Class<?> destinationCollectionClass, Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into the given destination collection.
Parameters | |
---|---|
Name | Description |
destinationCollectionClass | Class<?> class of destination collection (must have a public default constructor) |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
Returns | |
---|---|
Type | Description |
Collection<T> |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArrayAndClose(Class<?> destinationCollectionClass, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
public final Collection<T> <T>parseArrayAndClose(Class<?> destinationCollectionClass, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
Beta
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into
the given destination collection, optionally using the given parser customizer.
Parameters | |
---|---|
Name | Description |
destinationCollectionClass | Class<?> class of destination collection (must have a public default constructor) |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
customizeParser | CustomizeJsonParser optional parser customizer or |
Returns | |
---|---|
Type | Description |
Collection<T> |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArrayAndClose(Collection<? super T> destinationCollection, Class<T> destinationItemClass)
public final void <T>parseArrayAndClose(Collection<? super T> destinationCollection, Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into the given destination collection.
Parameters | |
---|---|
Name | Description |
destinationCollection | Collection<? super T> destination collection |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
Exceptions | |
---|---|
Type | Description |
IOException |
<T>parseArrayAndClose(Collection<? super T> destinationCollection, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
public final void <T>parseArrayAndClose(Collection<? super T> destinationCollection, Class<T> destinationItemClass, CustomizeJsonParser customizeParser)
Beta
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into
the given destination collection, optionally using the given parser customizer.
Parameters | |
---|---|
Name | Description |
destinationCollection | Collection<? super T> destination collection |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
customizeParser | CustomizeJsonParser optional parser customizer or |
Exceptions | |
---|---|
Type | Description |
IOException |
close()
public abstract void close()
Closes the parser and the underlying input stream or reader, and releases any memory associated with it.
Exceptions | |
---|---|
Type | Description |
IOException |
getBigIntegerValue()
public abstract BigInteger getBigIntegerValue()
Returns the BigInteger value of the current token.
Returns | |
---|---|
Type | Description |
BigInteger |
Exceptions | |
---|---|
Type | Description |
IOException |
getByteValue()
public abstract byte getByteValue()
Returns the byte value of the current token.
Returns | |
---|---|
Type | Description |
byte |
Exceptions | |
---|---|
Type | Description |
IOException |
getCurrentName()
public abstract String getCurrentName()
Returns the most recent field name or null
for array values or for root-level values.
Returns | |
---|---|
Type | Description |
String |
Exceptions | |
---|---|
Type | Description |
IOException |
getCurrentToken()
public abstract JsonToken getCurrentToken()
Returns the token the parser currently points to or null
for none (at start of input or
after end of input).
Returns | |
---|---|
Type | Description |
JsonToken |
getDecimalValue()
public abstract BigDecimal getDecimalValue()
Returns the BigDecimal value of the current token.
Returns | |
---|---|
Type | Description |
BigDecimal |
Exceptions | |
---|---|
Type | Description |
IOException |
getDoubleValue()
public abstract double getDoubleValue()
Returns the double value of the current token.
Returns | |
---|---|
Type | Description |
double |
Exceptions | |
---|---|
Type | Description |
IOException |
getFactory()
public abstract JsonFactory getFactory()
Returns the JSON factory from which this generator was created.
Returns | |
---|---|
Type | Description |
JsonFactory |
getFloatValue()
public abstract float getFloatValue()
Returns the float value of the current token.
Returns | |
---|---|
Type | Description |
float |
Exceptions | |
---|---|
Type | Description |
IOException |
getIntValue()
public abstract int getIntValue()
Returns the int value of the current token.
Returns | |
---|---|
Type | Description |
int |
Exceptions | |
---|---|
Type | Description |
IOException |
getLongValue()
public abstract long getLongValue()
Returns the long value of the current token.
Returns | |
---|---|
Type | Description |
long |
Exceptions | |
---|---|
Type | Description |
IOException |
getShortValue()
public abstract short getShortValue()
Returns the short value of the current token.
Returns | |
---|---|
Type | Description |
short |
Exceptions | |
---|---|
Type | Description |
IOException |
getText()
public abstract String getText()
Returns a textual representation of the current token or null
if #getCurrentToken() is null
.
Returns | |
---|---|
Type | Description |
String |
Exceptions | |
---|---|
Type | Description |
IOException |
nextToken()
public abstract JsonToken nextToken()
Returns the next token from the stream or null
to indicate end of input.
Returns | |
---|---|
Type | Description |
JsonToken |
Exceptions | |
---|---|
Type | Description |
IOException |
parse(Object destination)
public final void parse(Object destination)
Parse a JSON object from the given JSON parser into the given destination object.
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name. After this method ends, the current token will be the JsonToken#END_OBJECT of the current object.
Parameter | |
---|---|
Name | Description |
destination | Object destination object |
Exceptions | |
---|---|
Type | Description |
IOException |
parse(Object destination, CustomizeJsonParser customizeParser)
public final void parse(Object destination, CustomizeJsonParser customizeParser)
Beta
Parse a JSON object from the given JSON parser into the given destination object, optionally
using the given parser customizer.
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name. After this method ends, the current token will be the JsonToken#END_OBJECT of the current object.
Parameters | |
---|---|
Name | Description |
destination | Object destination object |
customizeParser | CustomizeJsonParser optional parser customizer or |
Exceptions | |
---|---|
Type | Description |
IOException |
parse(Type dataType, boolean close)
public Object parse(Type dataType, boolean close)
Parse a JSON object, array, or value into a new instance of the given destination class.
If it parses an object, after this method ends, the current token will be the object's ending JsonToken#END_OBJECT. If it parses an array, after this method ends, the current token will be the array's ending JsonToken#END_ARRAY.
Parameters | |
---|---|
Name | Description |
dataType | Type Type into which the JSON should be parsed |
close | boolean
|
Returns | |
---|---|
Type | Description |
Object | new instance of the parsed dataType |
Exceptions | |
---|---|
Type | Description |
IOException |
parse(Type dataType, boolean close, CustomizeJsonParser customizeParser)
public Object parse(Type dataType, boolean close, CustomizeJsonParser customizeParser)
Beta
Parse a JSON object, array, or value into a new instance of the given destination class,
optionally using the given parser customizer.
If it parses an object, after this method ends, the current token will be the object's ending JsonToken#END_OBJECT. If it parses an array, after this method ends, the current token will be the array's ending JsonToken#END_ARRAY.
Parameters | |
---|---|
Name | Description |
dataType | Type Type into which the JSON should be parsed |
close | boolean
|
customizeParser | CustomizeJsonParser optional parser customizer or |
Returns | |
---|---|
Type | Description |
Object | new instance of the parsed dataType |
Exceptions | |
---|---|
Type | Description |
IOException |
parseAndClose(Object destination)
public final void parseAndClose(Object destination)
Parse a JSON Object from the given JSON parser -- which is closed after parsing completes -- into the given destination object.
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name.
Parameter | |
---|---|
Name | Description |
destination | Object destination object |
Exceptions | |
---|---|
Type | Description |
IOException |
parseAndClose(Object destination, CustomizeJsonParser customizeParser)
public final void parseAndClose(Object destination, CustomizeJsonParser customizeParser)
Beta
Parse a JSON Object from the given JSON parser -- which is closed after parsing completes --
into the given destination object, optionally using the given parser customizer.
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name.
Parameters | |
---|---|
Name | Description |
destination | Object destination object |
customizeParser | CustomizeJsonParser optional parser customizer or |
Exceptions | |
---|---|
Type | Description |
IOException |
skipChildren()
public abstract JsonParser skipChildren()
Skips to the matching JsonToken#END_ARRAY if current token is JsonToken#START_ARRAY, the matching JsonToken#END_OBJECT if the current token is JsonToken#START_OBJECT, else does nothing.
Returns | |
---|---|
Type | Description |
JsonParser |
Exceptions | |
---|---|
Type | Description |
IOException |
skipToKey(String keyToFind)
public final void skipToKey(String keyToFind)
Skips the values of all keys in the current object until it finds the given key.
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name. After this method ends, the current token will either be the JsonToken#END_OBJECT of the current object if the key is not found, or the value of the key that was found.
Parameter | |
---|---|
Name | Description |
keyToFind | String key to find |
Exceptions | |
---|---|
Type | Description |
IOException |
skipToKey(Set<String> keysToFind)
public final String skipToKey(Set<String> keysToFind)
Skips the values of all keys in the current object until it finds one of the given keys.
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name. After this method ends, the current token will either be the JsonToken#END_OBJECT of the current object if no matching key is found, or the value of the key that was found.
Parameter | |
---|---|
Name | Description |
keysToFind | Set<String> set of keys to look for |
Returns | |
---|---|
Type | Description |
String | name of the first matching key found or |
Exceptions | |
---|---|
Type | Description |
IOException |