public abstract class JsonParser extends 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 BigInteger |
getBigIntegerValue()
Returns the
BigInteger value of the current token.
|
abstract byte |
getByteValue()
Returns the byte value of the current token.
|
abstract 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 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 String |
getText()
|
abstract JsonToken |
nextToken()
Returns the next token from the stream or
null to indicate end of input.
|
<T> T |
parse(Class
Parse a JSON object, array, or value into a new instance of the given destination class.
|
<T> T |
parse(Class
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(Object
Parse a JSON object from the given JSON parser into the given destination object.
|
void |
parse(Object
Beta
Parse a JSON object from the given JSON parser into the given destination object, optionally using the given parser customizer. |
Object |
parse(Type
Parse a JSON object, array, or value into a new instance of the given destination class.
|
Object |
parse(Type
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(Class
Parse a JSON object, array, or value into a new instance of the given destination class, and then closes the parser.
|
<T> T |
parseAndClose(Class
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(Object
Parse a JSON Object from the given JSON parser -- which is closed after parsing completes -- into the given destination object.
|
void |
parseAndClose(Object
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> Collection |
parseArray(Class
Parse a JSON Array from the given JSON parser into the given destination collection.
|
<T> Collection |
parseArray(Class
Beta
Parse a JSON Array from the given JSON parser into the given destination collection, optionally using the given parser customizer. |
<T> void |
parseArray(Collection
Parse a JSON Array from the given JSON parser into the given destination collection.
|
<T> void |
parseArray(Collection
Beta
Parse a JSON Array from the given JSON parser into the given destination collection, optionally using the given parser customizer. |
<T> Collection |
parseArrayAndClose(Class
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into the given destination collection.
|
<T> Collection |
parseArrayAndClose(Class
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(Collection
Parse a JSON Array from the given JSON parser (which is closed after parsing completes) into the given destination collection.
|
<T> void |
parseArrayAndClose(Collection
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 if current token is
JsonToken, the matching
JsonToken if the current token is
JsonToken, else does nothing.
|
String |
skipToKey(Set
Skips the values of all keys in the current object until it finds one of the given keys.
|
void |
skipToKey(String
Skips the values of all keys in the current object until it finds the given key.
|
public abstract JsonFactorygetFactory()
public abstract void close()
throws IOException
IOException
public abstract JsonTokennextToken() throws IOException
null to indicate end of input.
IOException
public abstract JsonTokengetCurrentToken()
null for none (at start of input or after end of input).
public abstract StringgetCurrentName() throws IOException
null for array values or for root-level values.
IOException
public abstract JsonParserskipChildren() throws 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.
IOException
public abstract StringgetText() throws IOException
IOException
public abstract byte getByteValue()
throws IOException
IOException
public abstract short getShortValue()
throws IOException
IOException
public abstract int getIntValue()
throws IOException
IOException
public abstract float getFloatValue()
throws IOException
IOException
public abstract long getLongValue()
throws IOException
IOException
public abstract double getDoubleValue()
throws IOException
IOException
public abstract BigIntegergetBigIntegerValue() throws IOException
BigInteger value of the current token.
IOException
public abstract BigDecimalgetDecimalValue() throws IOException
BigDecimal value of the current token.
IOException
public final <T> T parseAndClose(Class<T> destinationClass) throws IOException
T - destination class
destinationClass - destination class that has a public default constructor to use to create a new instance
IOException
@Beta public final <T> T parseAndClose(Class<T> destinationClass, CustomizeJsonParser customizeParser) throws IOException
Beta
parse(Class, CustomizeJsonParser), and then closes the parser.
T - destination class
destinationClass - destination class that has a public default constructor to use to create a new instance
customizeParser - optional parser customizer or
null for none
IOException
public final void skipToKey(StringkeyToFind) throws 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 of the current object if the key is not found, or the value of the key that was found.
keyToFind - key to find
IOException
public final StringskipToKey(Set <String > keysToFind) throws 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 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 for
null if no match was found
IOException
public final void parseAndClose(Objectdestination) throws 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 object
IOException
@Beta public final void parseAndClose(Objectdestination, CustomizeJsonParser customizeParser) throws 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 object
customizeParser - optional parser customizer or
null for none
IOException
public final <T> T parse(Class<T> destinationClass) throws IOException
If it parses an object, after this method ends, the current token will be the object's ending JsonToken. If it parses an array, after this method ends, the current token will be the array's ending JsonToken.
T - destination class
destinationClass - destination class that has a public default constructor to use to create a new instance
IOException
@Beta public final <T> T parse(Class<T> destinationClass, CustomizeJsonParser customizeParser) throws IOException
Beta
If it parses an object, after this method ends, the current token will be the object's ending JsonToken. If it parses an array, after this method ends, the current token will be the array's ending JsonToken.
T - destination class
destinationClass - destination class that has a public default constructor to use to create a new instance
customizeParser - optional parser customizer or
null for none
IOException
public Objectparse(Type dataType, boolean close) throws IOException
If it parses an object, after this method ends, the current token will be the object's ending JsonToken. If it parses an array, after this method ends, the current token will be the array's ending JsonToken.
dataType - Type into which the JSON should be parsed
close -
true if
close() should be called after parsing
IOException
@Beta public Objectparse(Type dataType, boolean close, CustomizeJsonParser customizeParser) throws IOException
Beta
If it parses an object, after this method ends, the current token will be the object's ending JsonToken. If it parses an array, after this method ends, the current token will be the array's ending JsonToken.
dataType - Type into which the JSON should be parsed
close -
true if
close() should be called after parsing
customizeParser - optional parser customizer or
null for none
IOException
public final void parse(Objectdestination) throws 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 of the current object.
destination - destination object
IOException
@Beta public final void parse(Objectdestination, CustomizeJsonParser customizeParser) throws 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 of the current object.
destination - destination object
customizeParser - optional parser customizer or
null for none
IOException
public final <T> Collection<T> parseArrayAndClose(Class <?> destinationCollectionClass, Class <T> destinationItemClass) throws IOException
destinationCollectionClass - class of destination collection (must have a public default constructor)
destinationItemClass - class of destination collection item (must have a public default constructor)
IOException
@Beta public final <T> Collection<T> parseArrayAndClose(Class <?> destinationCollectionClass, Class <T> destinationItemClass, CustomizeJsonParser customizeParser) throws 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 none
IOException
public final <T> void parseArrayAndClose(Collection<? super T> destinationCollection, Class <T> destinationItemClass) throws IOException
destinationCollection - destination collection
destinationItemClass - class of destination collection item (must have a public default constructor)
IOException
@Beta public final <T> void parseArrayAndClose(Collection<? super T> destinationCollection, Class <T> destinationItemClass, CustomizeJsonParser customizeParser) throws IOException
Beta
destinationCollection - destination collection
destinationItemClass - class of destination collection item (must have a public default constructor)
customizeParser - optional parser customizer or
null for none
IOException
public final <T> Collection<T> parseArray(Class <?> destinationCollectionClass, Class <T> destinationItemClass) throws IOException
destinationCollectionClass - class of destination collection (must have a public default constructor)
destinationItemClass - class of destination collection item (must have a public default constructor)
IOException
@Beta public final <T> Collection<T> parseArray(Class <?> destinationCollectionClass, Class <T> destinationItemClass, CustomizeJsonParser customizeParser) throws 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 none
IOException
public final <T> void parseArray(Collection<? super T> destinationCollection, Class <T> destinationItemClass) throws IOException
destinationCollection - destination collection
destinationItemClass - class of destination collection item (must have a public default constructor)
IOException
@Beta public final <T> void parseArray(Collection<? super T> destinationCollection, Class <T> destinationItemClass, CustomizeJsonParser customizeParser) throws IOException
Beta
destinationCollection - destination collection
destinationItemClass - class of destination collection item (must have a public default constructor)
customizeParser - optional parser customizer or
null for none
IOException