Jackson - JsonParser Class


Advertisements

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
1static class JsonParser.Feature
Enumeration that defines all togglable features for parsers.
2static 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
1protected JsonParser()
Default constructor
2protected JsonParser(int features)

Class Methods

S.N.Method & Description
1protected JsonParseException _constructError(String msg) - Helper method for constructing JsonParseExceptions based on current state of the parser.
2protected void _reportUnsupportedOperation() - Helper method to call for operations that are not supported by parser implementation.
3boolean 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).
4boolean 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).
5boolean 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)).
6abstract void clearCurrentToken() - Method called to "consume" the current token by effectively removing it so that hasCurrentToken() returns false, and getCurrentToken() null).
7abstract 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.
8JsonParser configure(JsonParser.Feature f, boolean state) - Method for enabling or disabling specified feature (check JsonParser.Feature for list of features)
9JsonParser disable(JsonParser.Feature f) - Method for disabling specified feature (check JsonParser.Feature for list of features)
10JsonParser enable(JsonParser.Feature f) - Method for enabling specified parser feature (check JsonParser.Feature for list of features)
11abstract 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.
12byte[] getBinaryValue() - Convenience alternative to getBinaryValue(Base64Variant) that defaults to using Base64Variants.getDefaultVariant() as the default encoding.
13abstract 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.
14boolean getBooleanValue() - Convenience accessor that can be called when the current token is JsonToken.VALUE_TRUE or JsonToken.VALUE_FALSE.
15byte 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.
16abstract ObjectCodec getCodec() - Accessor for ObjectCodec associated with this parser, if any.
17abstract JsonLocation getCurrentLocation() - Method that returns location of the last processed character; usually for error reporting purposes.
18abstract 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.
19abstract JsonToken getCurrentToken() - Accessor to find which token parser currently points to, if any; null will be returned if none.
20abstract int getCurrentTokenId() - Method similar to getCurrentToken() but that returns an int instead of JsonToken (enum value).
21abstract BigDecimal getDecimalValue() - Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT or JsonToken.VALUE_NUMBER_INT.
22abstract 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.
23abstract Object getEmbeddedObject() - Accessor that can be called if (and only if) the current token is JsonToken.VALUE_EMBEDDED_OBJECT.
24int getFeatureMask() - Bulk access method for getting state of all standard JsonParser.Features.
25abstract 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.
26Object 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.
27abstract 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.
28abstract JsonToken getLastClearedToken() - Method that can be called to get the last token that was cleared using clearCurrentToken().
29abstract 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.
30abstract 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.
31abstract Number getNumberValue() - Generic number value accessor method that will work for all kinds of numeric values.
32Object 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.
33abstract JsonStreamContext getParsingContext() - Method that can be used to access current parsing context reader is in.
34FormatSchema getSchema() - Method for accessing Schema that this parser uses, if any.
35short 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.
36abstract 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.
37abstract 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.
38abstract int getTextLength() - Accessor used with getTextCharacters(), to know length of String stored in returned buffer.
39abstract int getTextOffset() - Accessor used with getTextCharacters(), to know offset of the first text content character within buffer.
40abstract 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.
41Object 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.
42boolean getValueAsBoolean() - Method that will try to convert value of current token to a boolean.
43boolean getValueAsBoolean(boolean defaultValue) - Method that will try to convert value of current token to a boolean.
44double getValueAsDouble() - Method that will try to convert value of current token to a Java double.
45double getValueAsDouble(double defaultValue) - Method that will try to convert value of current token to a Java double.
46int getValueAsInt() - Method that will try to convert value of current token to a int.
47int getValueAsInt(int defaultValue) - Method that will try to convert value of current token to a int.
48long getValueAsLong() - Method that will try to convert value of current token to a long.
49long getValueAsLong(long defaultValue) - Method that will try to convert value of current token to a long.
50String getValueAsString() - Method that will try to convert value of current token to a String.
51abstract String getValueAsString(String defaultValue) - Method that will try to convert value of current token to a String.
52abstract boolean hasCurrentToken() - Method for checking whether parser currently points to a token (and data for that token is available).
53abstract 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.
54abstract boolean isClosed() - Method that can be called to determine whether this parser is closed or not.
55boolean isEnabled(JsonParser.Feature f) - Method for checking whether specified JsonParser.Feature is enabled.
56boolean 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.
57Boolean 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.
58boolean 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.
59int 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:
60long 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:
61String nextTextValue() - Method that fetches next token (as if calling nextToken()) and if it is JsonToken.VALUE_STRING returns contained String value; otherwise returns null.
62abstract JsonToken nextToken() - Main iteration method, which will advance stream enough to determine type of the next token, if any.
63abstract 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).
64abstract void overrideCurrentName(String name) - Method that can be used to change what is considered to be the current (field) name.
65int readBinaryValue(Base64Variant b64variant, OutputStream out) - Similar to readBinaryValue(OutputStream) but allows explicitly specifying base64 variant to use.
66int 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.
72int releaseBuffered(OutputStream out) - Method that can be called to push back any content that has been read but not consumed by the parser.
73int releaseBuffered(Writer w) - Method that can be called to push back any content that has been read but not consumed by the parser.
74boolean 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).
75abstract void setCodec(ObjectCodec c) - Setter that allows defining ObjectCodec associated with this parser, if any.
76JsonParser setFeatureMask(int mask) - Bulk set method for (re)settting states of all standard JsonParser.Features
77void setSchema(FormatSchema schema) - Method to call to make this parser use specified schema.
78abstract 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.
79abstract 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