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.
Name | Description |
destinationClass | Class<T> destination class that has a public default constructor to use to create a new instance |
Type | Description |
T | new instance of the parsed destination class |
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.
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 |
Type | Description |
T | new instance of the parsed destination class |
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.
Name | Description |
destinationClass | Class<T> destination class that has a public default constructor to use to create a new instance |
Type | Description |
T | new instance of the parsed destination class |
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.
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 |
Type | Description |
T | new instance of the parsed destination class |
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.
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) |
Type | Description |
Collection<T> |
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.
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 |
Type | Description |
Collection<T> |
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.
Name | Description |
destinationCollection | Collection<? super T> destination collection |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
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.
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 |
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.
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) |
Type | Description |
Collection<T> |
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.
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 |
Type | Description |
Collection<T> |
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.
Name | Description |
destinationCollection | Collection<? super T> destination collection |
destinationItemClass | Class<T> class of destination collection item (must have a public default constructor) |
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.
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 |
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.
Type | Description |
IOException |
getBigIntegerValue()
public abstract BigInteger getBigIntegerValue()
Returns the BigInteger value of the current token.
Type | Description |
BigInteger |
Type | Description |
IOException |
getByteValue()
public abstract byte getByteValue()
Returns the byte value of the current token.
Type | Description |
byte |
Type | Description |
IOException |
getCurrentName()
public abstract String getCurrentName()
Returns the most recent field name or null
for array values or for root-level values.
Type | Description |
String |
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).
Type | Description |
JsonToken |
getDecimalValue()
public abstract BigDecimal getDecimalValue()
Returns the BigDecimal value of the current token.
Type | Description |
BigDecimal |
Type | Description |
IOException |
getDoubleValue()
public abstract double getDoubleValue()
Returns the double value of the current token.
Type | Description |
double |
Type | Description |
IOException |
getFactory()
public abstract JsonFactory getFactory()
Returns the JSON factory from which this generator was created.
Type | Description |
JsonFactory |
getFloatValue()
public abstract float getFloatValue()
Returns the float value of the current token.
Type | Description |
float |
Type | Description |
IOException |
getIntValue()
public abstract int getIntValue()
Returns the int value of the current token.
Type | Description |
int |
Type | Description |
IOException |
getLongValue()
public abstract long getLongValue()
Returns the long value of the current token.
Type | Description |
long |
Type | Description |
IOException |
getShortValue()
public abstract short getShortValue()
Returns the short value of the current token.
Type | Description |
short |
Type | Description |
IOException |
getText()
public abstract String getText()
Returns a textual representation of the current token or null
if #getCurrentToken() is null
.
Type | Description |
String |
Type | Description |
IOException |
nextToken()
public abstract JsonToken nextToken()
Returns the next token from the stream or null
to indicate end of input.
Type | Description |
JsonToken |
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.
Name | Description |
destination | Object destination object |
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.
Name | Description |
destination | Object destination object |
customizeParser | CustomizeJsonParser optional parser customizer or |
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.
Name | Description |
dataType | Type Type into which the JSON should be parsed |
close | boolean
|
Type | Description |
Object | new instance of the parsed dataType |
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.
Name | Description |
dataType | Type Type into which the JSON should be parsed |
close | boolean
|
customizeParser | CustomizeJsonParser optional parser customizer or |
Type | Description |
Object | new instance of the parsed dataType |
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.
Name | Description |
destination | Object destination object |
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.
Name | Description |
destination | Object destination object |
customizeParser | CustomizeJsonParser optional parser customizer or |
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.
Type | Description |
JsonParser |
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.
Name | Description |
keyToFind | String key to find |
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.
Name | Description |
keysToFind | Set<String> set of keys to look for |
Type | Description |
String | name of the first matching key found or |
Type | Description |
IOException |