CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-fasterxml-jackson-core--jackson-core

Core Jackson processing abstractions (aka Streaming API), implementation for JSON

Pending
Overview
Eval results
Files

json-parsing.mddocs/

JSON Parsing

JsonParser provides streaming, token-based JSON parsing with efficient memory usage and support for all JSON data types. It processes JSON content incrementally, making it suitable for large documents and memory-constrained environments.

Core Parsing API

Token Navigation

public abstract JsonToken nextToken() throws IOException;
public abstract JsonToken getCurrentToken();
public abstract String getCurrentName() throws IOException;
public JsonToken nextValue() throws IOException;
public boolean hasCurrentToken();
public boolean hasToken(JsonToken t);
public boolean hasTokenId(int id);
public void clearCurrentToken();
public JsonToken getLastClearedToken();

Location Information

public abstract JsonLocation getTokenLocation();
public abstract JsonLocation getCurrentLocation();
public JsonStreamContext getParsingContext();

Token Types

public enum JsonToken {
    NOT_AVAILABLE(null, JsonTokenId.ID_NOT_AVAILABLE),
    START_OBJECT("{", JsonTokenId.ID_START_OBJECT),
    END_OBJECT("}", JsonTokenId.ID_END_OBJECT),
    START_ARRAY("[", JsonTokenId.ID_START_ARRAY),
    END_ARRAY("]", JsonTokenId.ID_END_ARRAY),
    FIELD_NAME(null, JsonTokenId.ID_FIELD_NAME),
    VALUE_STRING(null, JsonTokenId.ID_STRING),
    VALUE_NUMBER_INT(null, JsonTokenId.ID_NUMBER_INT),
    VALUE_NUMBER_FLOAT(null, JsonTokenId.ID_NUMBER_FLOAT),
    VALUE_TRUE("true", JsonTokenId.ID_TRUE),
    VALUE_FALSE("false", JsonTokenId.ID_FALSE),
    VALUE_NULL("null", JsonTokenId.ID_NULL);
    
    public String asString();
    public boolean isNumeric();
    public boolean isBoolean();
    public boolean isScalarValue();
    public boolean isStructStart();
    public boolean isStructEnd();
}

Value Access Methods

String Values

public abstract String getText() throws IOException;
public abstract char[] getTextCharacters() throws IOException;
public abstract int getTextLength() throws IOException;
public abstract int getTextOffset() throws IOException;
public abstract String getValueAsString() throws IOException;
public abstract String getValueAsString(String def) throws IOException;

Numeric Values

public abstract Number getNumberValue() throws IOException;
public abstract NumberType getNumberType() throws IOException;
public NumberTypeFP getNumberTypeFP() throws IOException;

public abstract int getIntValue() throws IOException;
public abstract long getLongValue() throws IOException;
public abstract BigInteger getBigIntegerValue() throws IOException;
public abstract float getFloatValue() throws IOException;
public abstract double getDoubleValue() throws IOException;
public abstract BigDecimal getDecimalValue() throws IOException;

public int getValueAsInt() throws IOException;
public int getValueAsInt(int def) throws IOException;
public long getValueAsLong() throws IOException;
public long getValueAsLong(long def) throws IOException;
public double getValueAsDouble() throws IOException;
public double getValueAsDouble(double def) throws IOException;

Boolean and Other Values

public boolean getBooleanValue() throws IOException;
public boolean getValueAsBoolean() throws IOException;
public boolean getValueAsBoolean(boolean def) throws IOException;
public byte[] getBinaryValue() throws IOException;
public byte[] getBinaryValue(Base64Variant variant) throws IOException;

Number Types

public enum NumberType {
    INT, LONG, BIG_INTEGER, FLOAT, DOUBLE, BIG_DECIMAL;
    
    public String toString();
}

public enum NumberTypeFP {
    UNKNOWN("?"), FLOAT32("32-bit"), FLOAT64("64-bit"), BIG_DECIMAL("BigDecimal");
    
    public String toString();
}

Parsing Features

JSON Read Features

public enum JsonReadFeature implements FormatFeature {
    ALLOW_JAVA_COMMENTS(false),
    ALLOW_YAML_COMMENTS(false),
    ALLOW_SINGLE_QUOTES(false),
    ALLOW_UNQUOTED_FIELD_NAMES(false),
    ALLOW_UNESCAPED_CONTROL_CHARS(false),
    ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER(false),
    ALLOW_NUMERIC_LEADING_ZEROS(false),
    ALLOW_NON_NUMERIC_NUMBERS(false),
    ALLOW_MISSING_VALUES(false),
    ALLOW_TRAILING_COMMA(false),
    ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS(false),
    ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS(false),
    ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS(false);
    
    public boolean enabledByDefault();
    public boolean enabledIn(int flags);
    public int getMask();
}

Stream Read Features

public enum StreamReadFeature implements JacksonFeature {
    AUTO_CLOSE_SOURCE(true),
    STRICT_DUPLICATE_DETECTION(false),
    IGNORE_UNDEFINED(false),
    INCLUDE_SOURCE_IN_LOCATION(true),
    USE_FAST_DOUBLE_PARSER(true),
    USE_FAST_BIG_NUMBER_PARSER(true);
    
    public boolean enabledByDefault();
    public boolean enabledIn(int flags);
    public int getMask();
}

Advanced Parsing

Skip Methods

public JsonParser skipChildren() throws IOException;
public void finishToken() throws IOException;

Configuration and Status

public abstract boolean isClosed();
public JsonParser enable(StreamReadFeature f);
public JsonParser disable(StreamReadFeature f);
public boolean isEnabled(StreamReadFeature f);
public int getFeatureMask();
public JsonParser setFeatureMask(int mask);

Object Codec Integration

public ObjectCodec getCodec();
public void setCodec(ObjectCodec c);
public <T> T readValueAs(Class<T> valueType) throws IOException;
public <T> T readValueAs(TypeReference<T> valueTypeRef) throws IOException;
public <T> Iterator<T> readValuesAs(Class<T> valueType) throws IOException;
public <T> Iterator<T> readValuesAs(TypeReference<T> valueTypeRef) throws IOException;

Usage Examples

Basic Parsing Loop

JsonParser parser = factory.createParser(jsonString);
while (parser.nextToken() != null) {
    JsonToken token = parser.getCurrentToken();
    switch (token) {
        case START_OBJECT:
            // Handle object start
            break;
        case FIELD_NAME:
            String fieldName = parser.getCurrentName();
            // Handle field name
            break;
        case VALUE_STRING:
            String stringValue = parser.getText();
            // Handle string value
            break;
        case VALUE_NUMBER_INT:
            int intValue = parser.getIntValue();
            // Handle integer value
            break;
        // ... handle other token types
    }
}
parser.close();

Processing Specific Object Structure

// Expecting: {"users": [{"name": "John", "age": 30}, ...]}
JsonParser parser = factory.createParser(jsonInput);

parser.nextToken(); // START_OBJECT
parser.nextToken(); // FIELD_NAME "users"
parser.nextToken(); // START_ARRAY

while (parser.nextToken() == JsonToken.START_OBJECT) {
    String name = null;
    int age = 0;
    
    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = parser.getCurrentName();
        parser.nextToken();
        
        switch (fieldName) {
            case "name":
                name = parser.getValueAsString();
                break;
            case "age":
                age = parser.getValueAsInt();
                break;
        }
    }
    
    System.out.println("User: " + name + ", Age: " + age);
}

parser.close();

Error Handling

try {
    JsonParser parser = factory.createParser(jsonInput);
    // ... parsing logic
    parser.close();
} catch (JsonParseException e) {
    System.err.println("Parse error at " + e.getLocation() + ": " + e.getMessage());
} catch (IOException e) {
    System.err.println("IO error: " + e.getMessage());
}

With Features

JsonFactory factory = JsonFactory.builder()
    .enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
    .enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
    .build();

JsonParser parser = factory.createParser(jsonWithComments);
// Parser will now accept Java-style comments and single quotes

Binary Data Handling

public byte[] getBinaryValue() throws IOException;
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException;
public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IOException;

Example:

// JSON: {"data": "SGVsbG8gV29ybGQ="}
if (parser.getCurrentToken() == JsonToken.VALUE_STRING) {
    byte[] data = parser.getBinaryValue(); // Decodes base64 automatically
    String decoded = new String(data, StandardCharsets.UTF_8); // "Hello World"
}

Install with Tessl CLI

npx tessl i tessl/maven-com-fasterxml-jackson-core--jackson-core

docs

exception-handling.md

factory-configuration.md

features-configuration.md

index.md

json-generation.md

json-parsing.md

utilities-advanced.md

tile.json