public abstract class JsonParser
extends java.lang.Object
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
ArrayMap
is used by default for the parsed values.
Constructor and Description |
---|
JsonParser() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Closes the parser and the underlying input stream or reader, and releases any memory associated
with it.
|
abstract java.math.BigInteger |
getBigIntegerValue()
Returns the
BigInteger value of the current token. |
abstract byte |
getByteValue()
Returns the byte value of the current token.
|
abstract java.lang.String |
getCurrentName()
Returns the most recent field name or
null for array values or for root-level values. |
abstract JsonToken |
getCurrentToken()
Returns the token the parser currently points to or
null for none (at start of input or
after end of input). |
abstract java.math.BigDecimal |
getDecimalValue()
Returns the
BigDecimal value of the current token. |
abstract double |
getDoubleValue()
Returns the double value of the current token.
|
abstract JsonFactory |
getFactory()
Returns the JSON factory from which this generator was created.
|
abstract float |
getFloatValue()
Returns the float value of the current token.
|
abstract int |
getIntValue()
Returns the int value of the current token.
|
abstract long |
getLongValue()
Returns the long value of the current token.
|
abstract short |
getShortValue()
Returns the short value of the current token.
|
abstract java.lang.String |
getText()
|
abstract JsonToken |
nextToken()
Returns the next token from the stream or
null to indicate end of input. |
<T> T |
parse(java.lang.Class<T> destinationClass)
Parse a JSON object, array, or value into a new instance of the given destination class.
|
<T> T |
parse(java.lang.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. |
void |
parse(java.lang.Object destination)
Parse a JSON object from the given JSON parser into the given destination object.
|
void |
parse(java.lang.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. |
java.lang.Object |
parse(java.lang.reflect.Type dataType,
boolean close)
Parse a JSON object, array, or value into a new instance of the given destination class.
|
java.lang.Object |
parse(java.lang.reflect.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. |
<T> T |
parseAndClose(java.lang.Class<T> destinationClass)
Parse a JSON object, array, or value into a new instance of the given destination class, and
then closes the parser.
|
<T> T |
parseAndClose(java.lang.Class<T> destinationClass,
CustomizeJsonParser customizeParser)
Beta Parse a JSON object, array, or value into a new instance of the given destination class using parse(Class, CustomizeJsonParser) , and then closes the parser. |
void |
parseAndClose(java.lang.Object destination)
Parse a JSON Object from the given JSON parser -- which is closed after parsing completes --
into the given destination object.
|
void |
parseAndClose(java.lang.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. |
<T> java.util.Collection<T> |
parseArray(java.lang.Class<?> destinationCollectionClass,
java.lang.Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser into the given destination collection.
|
<T> java.util.Collection<T> |
parseArray(java.lang.Class<?> destinationCollectionClass,
java.lang.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. |
<T> void |
parseArray(java.util.Collection<? super T> destinationCollection,
java.lang.Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser into the given destination collection.
|
<T> void |
parseArray(java.util.Collection<? super T> destinationCollection,
java.lang.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. |
<T> java.util.Collection<T> |
parseArrayAndClose(java.lang.Class<?> destinationCollectionClass,
java.lang.Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into
the given destination collection.
|
<T> java.util.Collection<T> |
parseArrayAndClose(java.lang.Class<?> destinationCollectionClass,
java.lang.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. |
<T> void |
parseArrayAndClose(java.util.Collection<? super T> destinationCollection,
java.lang.Class<T> destinationItemClass)
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into
the given destination collection.
|
<T> void |
parseArrayAndClose(java.util.Collection<? super T> destinationCollection,
java.lang.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. |
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. |
java.lang.String |
skipToKey(java.util.Set<java.lang.String> keysToFind)
Skips the values of all keys in the current object until it finds one of the given keys.
|
void |
skipToKey(java.lang.String keyToFind)
Skips the values of all keys in the current object until it finds the given key.
|
public abstract JsonFactory getFactory()
public abstract void close() throws java.io.IOException
java.io.IOException
public abstract JsonToken nextToken() throws java.io.IOException
null
to indicate end of input.java.io.IOException
public abstract JsonToken getCurrentToken()
null
for none (at start of input or
after end of input).public abstract java.lang.String getCurrentName() throws java.io.IOException
null
for array values or for root-level values.java.io.IOException
public abstract JsonParser skipChildren() throws java.io.IOException
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.java.io.IOException
public abstract java.lang.String getText() throws java.io.IOException
java.io.IOException
public abstract byte getByteValue() throws java.io.IOException
java.io.IOException
public abstract short getShortValue() throws java.io.IOException
java.io.IOException
public abstract int getIntValue() throws java.io.IOException
java.io.IOException
public abstract float getFloatValue() throws java.io.IOException
java.io.IOException
public abstract long getLongValue() throws java.io.IOException
java.io.IOException
public abstract double getDoubleValue() throws java.io.IOException
java.io.IOException
public abstract java.math.BigInteger getBigIntegerValue() throws java.io.IOException
BigInteger
value of the current token.java.io.IOException
public abstract java.math.BigDecimal getDecimalValue() throws java.io.IOException
BigDecimal
value of the current token.java.io.IOException
public final <T> T parseAndClose(java.lang.Class<T> destinationClass) throws java.io.IOException
T
- destination classdestinationClass
- destination class that has a public default constructor to use to
create a new instancejava.io.IOException
@Beta public final <T> T parseAndClose(java.lang.Class<T> destinationClass, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
parse(Class, CustomizeJsonParser)
, and then closes the parser.T
- destination classdestinationClass
- destination class that has a public default constructor to use to
create a new instancecustomizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final void skipToKey(java.lang.String keyToFind) throws java.io.IOException
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.
keyToFind
- key to findjava.io.IOException
public final java.lang.String skipToKey(java.util.Set<java.lang.String> keysToFind) throws java.io.IOException
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.
keysToFind
- set of keys to look fornull
if no match was foundjava.io.IOException
public final void parseAndClose(java.lang.Object destination) throws java.io.IOException
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name.
destination
- destination objectjava.io.IOException
@Beta public final void parseAndClose(java.lang.Object destination, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
Before this method is called, the parser must either point to the start or end of a JSON object or to a field name.
destination
- destination objectcustomizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final <T> T parse(java.lang.Class<T> destinationClass) throws java.io.IOException
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
.
T
- destination classdestinationClass
- destination class that has a public default constructor to use to
create a new instancejava.io.IOException
@Beta public final <T> T parse(java.lang.Class<T> destinationClass, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
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
.
T
- destination classdestinationClass
- destination class that has a public default constructor to use to
create a new instancecustomizeParser
- optional parser customizer or null
for nonejava.io.IOException
public java.lang.Object parse(java.lang.reflect.Type dataType, boolean close) throws java.io.IOException
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
.
dataType
- Type into which the JSON should be parsedclose
- true
if close()
should be called after parsingjava.io.IOException
@Beta public java.lang.Object parse(java.lang.reflect.Type dataType, boolean close, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
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
.
dataType
- Type into which the JSON should be parsedclose
- true
if close()
should be called after parsingcustomizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final void parse(java.lang.Object destination) throws java.io.IOException
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.
destination
- destination objectjava.io.IOException
@Beta public final void parse(java.lang.Object destination, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
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.
destination
- destination objectcustomizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final <T> java.util.Collection<T> parseArrayAndClose(java.lang.Class<?> destinationCollectionClass, java.lang.Class<T> destinationItemClass) throws java.io.IOException
destinationCollectionClass
- class of destination collection (must have a public default
constructor)destinationItemClass
- class of destination collection item (must have a public default
constructor)java.io.IOException
@Beta public final <T> java.util.Collection<T> parseArrayAndClose(java.lang.Class<?> destinationCollectionClass, java.lang.Class<T> destinationItemClass, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
destinationCollectionClass
- class of destination collection (must have a public default
constructor)destinationItemClass
- class of destination collection item (must have a public default
constructor)customizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final <T> void parseArrayAndClose(java.util.Collection<? super T> destinationCollection, java.lang.Class<T> destinationItemClass) throws java.io.IOException
destinationCollection
- destination collectiondestinationItemClass
- class of destination collection item (must have a public default
constructor)java.io.IOException
@Beta public final <T> void parseArrayAndClose(java.util.Collection<? super T> destinationCollection, java.lang.Class<T> destinationItemClass, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
destinationCollection
- destination collectiondestinationItemClass
- class of destination collection item (must have a public default
constructor)customizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final <T> java.util.Collection<T> parseArray(java.lang.Class<?> destinationCollectionClass, java.lang.Class<T> destinationItemClass) throws java.io.IOException
destinationCollectionClass
- class of destination collection (must have a public default
constructor)destinationItemClass
- class of destination collection item (must have a public default
constructor)java.io.IOException
@Beta public final <T> java.util.Collection<T> parseArray(java.lang.Class<?> destinationCollectionClass, java.lang.Class<T> destinationItemClass, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
destinationCollectionClass
- class of destination collection (must have a public default
constructor)destinationItemClass
- class of destination collection item (must have a public default
constructor)customizeParser
- optional parser customizer or null
for nonejava.io.IOException
public final <T> void parseArray(java.util.Collection<? super T> destinationCollection, java.lang.Class<T> destinationItemClass) throws java.io.IOException
destinationCollection
- destination collectiondestinationItemClass
- class of destination collection item (must have a public default
constructor)java.io.IOException
@Beta public final <T> void parseArray(java.util.Collection<? super T> destinationCollection, java.lang.Class<T> destinationItemClass, CustomizeJsonParser customizeParser) throws java.io.IOException
Beta
destinationCollection
- destination collectiondestinationItemClass
- class of destination collection item (must have a public default
constructor)customizeParser
- optional parser customizer or null
for nonejava.io.IOException
Copyright © 2011-2018 Google. All Rights Reserved.