Jackson - JsonParser Class
Introduction
JsonParser is the base class to define public API for reading Json content. Instances are created using factory methods of a JsonFactory instance.
Class declaration
Following is the declaration for com.fasterxml.jackson.core.JsonParser class:
public abstract class JsonParser extends Object implements Closeable, Versioned
Nested Classes
S.N. | Class & Description |
---|---|
1 | static class JsonParser.Feature Enumeration that defines all togglable features for parsers. |
2 | static class JsonParser.NumberType Enumeration of possible "native" (optimal) types that can be used for numbers. |
Fields
protected int _features - Bit flag composed of bits that indicate which JsonParser.Features are enabled.
Constructors
S.N. | Constructor & Description |
---|---|
1 | protected JsonParser() Default constructor |
2 | protected JsonParser(int features) |
Class Methods
S.N. | Method & Description |
---|---|
1 | protected JsonParseException _constructError(String msg) - Helper method for constructing JsonParseExceptions based on current state of the parser. |
2 | protected void _reportUnsupportedOperation() - Helper method to call for operations that are not supported by parser implementation. |
3 | boolean canReadObjectId() - Introspection method that may be called to see if the underlying data format supports some kind of Object Ids natively (many do not; for example, JSON doesn't). |
4 | boolean canReadTypeId() - Introspection method that may be called to see if the underlying data format supports some kind of Type Ids natively (many do not; for example, JSON doesn't). |
5 | boolean canUseSchema(FormatSchema schema) - Method that can be used to verify that given schema can be used with this parser (using setSchema(com.fasterxml.jackson.core.FormatSchema)). |
6 | abstract void clearCurrentToken() - Method called to "consume" the current token by effectively removing it so that hasCurrentToken() returns false, and getCurrentToken() null). |
7 | abstract void close() - Closes the parser so that no further iteration or data access can be made; will also close the underlying input source if parser either owns the input source, or feature JsonParser.Feature.AUTO_CLOSE_SOURCE is enabled. |
8 | JsonParser configure(JsonParser.Feature f, boolean state) - Method for enabling or disabling specified feature (check JsonParser.Feature for list of features) |
9 | JsonParser disable(JsonParser.Feature f) - Method for disabling specified feature (check JsonParser.Feature for list of features) |
10 | JsonParser enable(JsonParser.Feature f) - Method for enabling specified parser feature (check JsonParser.Feature for list of features) |
11 | abstract BigInteger getBigIntegerValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can not be used as a Java long primitive type due to its magnitude. |
12 | byte[] getBinaryValue() - Convenience alternative to getBinaryValue(Base64Variant) that defaults to using Base64Variants.getDefaultVariant() as the default encoding. |
13 | abstract byte[] getBinaryValue(Base64Variant b64variant) - Method that can be used to read (and consume -- results may not be accessible using other methods after the call) base64-encoded binary data included in the current textual JSON value. |
14 | boolean getBooleanValue() - Convenience accessor that can be called when the current token is JsonToken.VALUE_TRUE or JsonToken.VALUE_FALSE. |
15 | byte getByteValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a value of Java byte primitive type. |
16 | abstract ObjectCodec getCodec() - Accessor for ObjectCodec associated with this parser, if any. |
17 | abstract JsonLocation getCurrentLocation() - Method that returns location of the last processed character; usually for error reporting purposes. |
18 | abstract String getCurrentName() - Method that can be called to get the name associated with the current token: for JsonToken.FIELD_NAMEs it will be the same as what getText() returns; for field values it will be preceding field name; and for others (array values, root-level values) null. |
19 | abstract JsonToken getCurrentToken() - Accessor to find which token parser currently points to, if any; null will be returned if none. |
20 | abstract int getCurrentTokenId() - Method similar to getCurrentToken() but that returns an int instead of JsonToken (enum value). |
21 | abstract BigDecimal getDecimalValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT or JsonToken.VALUE_NUMBER_INT. |
22 | abstract double getDoubleValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java double primitive type. |
23 | abstract Object getEmbeddedObject() - Accessor that can be called if (and only if) the current token is JsonToken.VALUE_EMBEDDED_OBJECT. |
24 | int getFeatureMask() - Bulk access method for getting state of all standard JsonParser.Features. |
25 | abstract float getFloatValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java float primitive type. |
26 | Object getInputSource() - Method that can be used to get access to object that is used to access input being parsed; this is usually either InputStream or Reader, depending on what parser was constructed with. |
27 | abstract int getIntValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a value of Java int primitive type. |
28 | abstract JsonToken getLastClearedToken() - Method that can be called to get the last token that was cleared using clearCurrentToken(). |
29 | abstract long getLongValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type. |
30 | abstract JsonParser.NumberType getNumberType() - If current token is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of JsonParser.NumberType constants; otherwise returns null. |
31 | abstract Number getNumberValue() - Generic number value accessor method that will work for all kinds of numeric values. |
32 | Object getObjectId() - Method that can be called to check whether current token (one that was just read) has an associated Object id, and if so, return it. |
33 | abstract JsonStreamContext getParsingContext() - Method that can be used to access current parsing context reader is in. |
34 | FormatSchema getSchema() - Method for accessing Schema that this parser uses, if any. |
35 | short getShortValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a value of Java short primitive type. |
36 | abstract String getText() - Method for accessing textual representation of the current token; if no current token (before first call to nextToken(), or after encountering end-of-input), returns null. |
37 | abstract char[] getTextCharacters() - Method similar to getText(), but that will return underlying (unmodifiable) character array that contains textual value, instead of constructing a String object to contain this information. |
38 | abstract int getTextLength() - Accessor used with getTextCharacters(), to know length of String stored in returned buffer. |
39 | abstract int getTextOffset() - Accessor used with getTextCharacters(), to know offset of the first text content character within buffer. |
40 | abstract JsonLocation getTokenLocation() - Method that return the starting location of the current token; that is, position of the first character from input that starts the current token. |
41 | Object getTypeId() - Method that can be called to check whether current token (one that was just read) has an associated type id, and if so, return it. |
42 | boolean getValueAsBoolean() - Method that will try to convert value of current token to a boolean. |
43 | boolean getValueAsBoolean(boolean defaultValue) - Method that will try to convert value of current token to a boolean. |
44 | double getValueAsDouble() - Method that will try to convert value of current token to a Java double. |
45 | double getValueAsDouble(double defaultValue) - Method that will try to convert value of current token to a Java double. |
46 | int getValueAsInt() - Method that will try to convert value of current token to a int. |
47 | int getValueAsInt(int defaultValue) - Method that will try to convert value of current token to a int. |
48 | long getValueAsLong() - Method that will try to convert value of current token to a long. |
49 | long getValueAsLong(long defaultValue) - Method that will try to convert value of current token to a long. |
50 | String getValueAsString() - Method that will try to convert value of current token to a String. |
51 | abstract String getValueAsString(String defaultValue) - Method that will try to convert value of current token to a String. |
52 | abstract boolean hasCurrentToken() - Method for checking whether parser currently points to a token (and data for that token is available). |
53 | abstract boolean hasTextCharacters() - Method that can be used to determine whether calling of getTextCharacters() would be the most efficient way to access textual content for the event parser currently points to. |
54 | abstract boolean isClosed() - Method that can be called to determine whether this parser is closed or not. |
55 | boolean isEnabled(JsonParser.Feature f) - Method for checking whether specified JsonParser.Feature is enabled. |
56 | boolean isExpectedStartArrayToken() - Specialized accessor that can be used to verify that the current token indicates start array (usually meaning that current token is JsonToken.START_ARRAY) when start array is expected. |
57 | Boolean nextBooleanValue() - Method that fetches next token (as if calling nextToken()) and if it is JsonToken.VALUE_TRUE or JsonToken.VALUE_FALSE returns matching Boolean value; otherwise return null. |
58 | boolean nextFieldName(SerializableString str) - Method that fetches next token (as if calling nextToken()) and verifies whether it is JsonToken.FIELD_NAME with specified name and returns result of that comparison. |
59 | int nextIntValue(int defaultValue) - Method that fetches next token (as if calling nextToken()) and if it is JsonToken.VALUE_NUMBER_INT returns 32-bit int value; otherwise returns specified default value It is functionally equivalent to: |
60 | long nextLongValue(long defaultValue) - Method that fetches next token (as if calling nextToken()) and if it is JsonToken.VALUE_NUMBER_INT returns 64-bit long value; otherwise returns specified default value It is functionally equivalent to: |
61 | String nextTextValue() - Method that fetches next token (as if calling nextToken()) and if it is JsonToken.VALUE_STRING returns contained String value; otherwise returns null. |
62 | abstract JsonToken nextToken() - Main iteration method, which will advance stream enough to determine type of the next token, if any. |
63 | abstract JsonToken nextValue() - Iteration method that will advance stream enough to determine type of the next token that is a value type (including JSON Array and Object start/end markers). |
64 | abstract void overrideCurrentName(String name) - Method that can be used to change what is considered to be the current (field) name. |
65 | int readBinaryValue(Base64Variant b64variant, OutputStream out) - Similar to readBinaryValue(OutputStream) but allows explicitly specifying base64 variant to use. |
66 | int readBinaryValue(OutputStream out) - Method that can be used as an alternative to getBigIntegerValue(), especially when value can be large. |
67 | <T> T readValueAs(Class<T> valueType) - Method to deserialize JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (like Boolean). |
68 | <T> T readValueAs(TypeReference<?> valueTypeRef)- Method to deserialize JSON content into a Java type, reference to which is passed as argument. |
69 | <T extends TreeNode> T readValueAsTree() - Method to deserialize JSON content into equivalent "tree model", represented by root TreeNode of resulting model. |
70 | <T> Iterator<T> readValuesAs(Class<T> valueType) - Method for reading sequence of Objects from parser stream, all with same specified value type. |
71 | <T> Iterator<T> readValuesAs(TypeReference<?> valueTypeRef)- Method for reading sequence of Objects from parser stream, all with same specified value type. |
72 | int releaseBuffered(OutputStream out) - Method that can be called to push back any content that has been read but not consumed by the parser. |
73 | int releaseBuffered(Writer w) - Method that can be called to push back any content that has been read but not consumed by the parser. |
74 | boolean requiresCustomCodec() - Method that can be called to determine if a custom ObjectCodec is needed for binding data parsed using JsonParser constructed by this factory (which typically also implies the same for serialization with JsonGenerator). |
75 | abstract void setCodec(ObjectCodec c) - Setter that allows defining ObjectCodec associated with this parser, if any. |
76 | JsonParser setFeatureMask(int mask) - Bulk set method for (re)settting states of all standard JsonParser.Features |
77 | void setSchema(FormatSchema schema) - Method to call to make this parser use specified schema. |
78 | abstract JsonParser skipChildren() - Method that will skip all child tokens of an array or object token that the parser currently points to, iff stream points to JsonToken.START_OBJECT or JsonToken.START_ARRAY. |
79 | abstract Version version() - Accessor for getting version of the core package, given a parser instance. |
Methods inherited
This class inherits methods from the following classes:
java.lang.Object
Advertisements