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

features-configuration.mddocs/

Features and Configuration

Jackson Core provides extensive configuration options through feature enums and constraint classes, allowing fine-tuned control over parsing and generation behavior for performance, security, and compatibility requirements.

Stream Features

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();
}

Feature Details:

  • AUTO_CLOSE_SOURCE: Automatically close input sources when parser is closed
  • STRICT_DUPLICATE_DETECTION: Detect and reject duplicate JSON object keys
  • IGNORE_UNDEFINED: Ignore undefined values during parsing
  • INCLUDE_SOURCE_IN_LOCATION: Include source reference in location information
  • USE_FAST_DOUBLE_PARSER: Use optimized double parsing for better performance
  • USE_FAST_BIG_NUMBER_PARSER: Use optimized BigDecimal/BigInteger parsing

Stream Write Features

public enum StreamWriteFeature implements JacksonFeature {
    AUTO_CLOSE_TARGET(true),
    AUTO_CLOSE_JSON_CONTENT(true),
    FLUSH_PASSED_TO_STREAM(true),
    WRITE_BIGDECIMAL_AS_PLAIN(false),
    STRICT_DUPLICATE_DETECTION(false),
    IGNORE_UNKNOWN(false);
    
    public boolean enabledByDefault();
    public boolean enabledIn(int flags);
    public int getMask();
}

Feature Details:

  • AUTO_CLOSE_TARGET: Automatically close output targets when generator is closed
  • AUTO_CLOSE_JSON_CONTENT: Automatically close incomplete JSON structures
  • FLUSH_PASSED_TO_STREAM: Pass flush() calls to underlying output stream
  • WRITE_BIGDECIMAL_AS_PLAIN: Write BigDecimal using plain notation (no scientific)
  • STRICT_DUPLICATE_DETECTION: Detect and reject duplicate field names during generation
  • IGNORE_UNKNOWN: Ignore unknown configuration settings

JSON-Specific 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();
}

Feature Details:

  • ALLOW_JAVA_COMMENTS: Accept Java/C++ style comments (// and /* */)
  • ALLOW_YAML_COMMENTS: Accept YAML style comments (#)
  • ALLOW_SINGLE_QUOTES: Accept single quotes around strings and field names
  • ALLOW_UNQUOTED_FIELD_NAMES: Accept unquoted field names
  • ALLOW_UNESCAPED_CONTROL_CHARS: Accept unescaped control characters in strings
  • ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER: Allow backslash escaping of any character
  • ALLOW_NUMERIC_LEADING_ZEROS: Accept numbers with leading zeros
  • ALLOW_NON_NUMERIC_NUMBERS: Accept special float values (NaN, Infinity)
  • ALLOW_MISSING_VALUES: Accept missing values in arrays/objects
  • ALLOW_TRAILING_COMMA: Accept trailing commas in arrays and objects
  • ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS: Accept trailing decimal points
  • ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS: Accept leading decimal points
  • ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS: Accept leading plus signs in numbers

JSON Write Features

public enum JsonWriteFeature implements FormatFeature {
    QUOTE_FIELD_NAMES(true),
    WRITE_NAN_AS_STRINGS(false),
    WRITE_NUMBERS_AS_STRINGS(false),
    ESCAPE_NON_ASCII(false),
    WRITE_BIGDECIMAL_AS_PLAIN(false);
    
    public boolean enabledByDefault();
    public boolean enabledIn(int flags);
    public int getMask();
}

Feature Details:

  • QUOTE_FIELD_NAMES: Quote JSON field names (standard JSON)
  • WRITE_NAN_AS_STRINGS: Write NaN and Infinity as quoted strings
  • WRITE_NUMBERS_AS_STRINGS: Write all numeric values as quoted strings
  • ESCAPE_NON_ASCII: Escape all non-ASCII characters
  • WRITE_BIGDECIMAL_AS_PLAIN: Write BigDecimal values in plain notation

Constraints

Stream Read Constraints

public final class StreamReadConstraints implements Serializable {
    public static final int DEFAULT_MAX_STRING_LEN = 20_000_000;
    public static final int DEFAULT_MAX_NUMBER_LEN = 1000;
    public static final int DEFAULT_MAX_DEPTH = 1000;
    public static final long DEFAULT_MAX_DOC_LEN = -1L;
    public static final int DEFAULT_MAX_NAME_LEN = 50000;
    
    public static Builder builder();
    public static StreamReadConstraints defaults();
    
    public int getMaxStringLength();
    public int getMaxNumberLength();
    public int getMaxNestingDepth();
    public long getMaxDocumentLength();
    public int getMaxNameLength();
    
    public static class Builder {
        public Builder maxStringLength(int maxStringLength);
        public Builder maxNumberLength(int maxNumberLength);
        public Builder maxNestingDepth(int maxNestingDepth);
        public Builder maxDocumentLength(long maxDocumentLength);
        public Builder maxNameLength(int maxNameLength);
        public StreamReadConstraints build();
    }
}

Stream Write Constraints

public final class StreamWriteConstraints implements Serializable {
    public static final int DEFAULT_MAX_DEPTH = 1000;
    
    public static Builder builder();
    public static StreamWriteConstraints defaults();
    
    public int getMaxNestingDepth();
    
    public static class Builder {
        public Builder maxNestingDepth(int maxNestingDepth);
        public StreamWriteConstraints build();
    }
}

Factory Features

JsonFactory Features

public enum Feature implements JacksonFeature {
    INTERN_FIELD_NAMES(true),
    CANONICALIZE_FIELD_NAMES(true),
    FAIL_ON_SYMBOL_HASH_OVERFLOW(true),
    USE_FAST_DOUBLE_PARSER(true),
    USE_FAST_BIG_NUMBER_PARSER(true),
    USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING(true);
    
    public boolean enabledByDefault();
    public boolean enabledIn(int flags);
    public int getMask();
}

Feature Details:

  • INTERN_FIELD_NAMES: Intern field names for memory efficiency
  • CANONICALIZE_FIELD_NAMES: Canonicalize field names (required for interning)
  • FAIL_ON_SYMBOL_HASH_OVERFLOW: Fail when symbol table hash overflow detected (DoS protection)
  • USE_FAST_DOUBLE_PARSER: Use fast double parser implementation
  • USE_FAST_BIG_NUMBER_PARSER: Use fast BigDecimal/BigInteger parser
  • USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING: Use thread-local buffer recycling

Feature Management

Parser Feature Control

public JsonParser enable(StreamReadFeature f);
public JsonParser disable(StreamReadFeature f);
public JsonParser configure(StreamReadFeature f, boolean state);
public boolean isEnabled(StreamReadFeature f);
public int getFeatureMask();
public JsonParser setFeatureMask(int mask);

Generator Feature Control

public JsonGenerator enable(StreamWriteFeature f);
public JsonGenerator disable(StreamWriteFeature f);  
public JsonGenerator configure(StreamWriteFeature f, boolean state);
public boolean isEnabled(StreamWriteFeature f);
public int getFeatureMask();
public JsonGenerator setFeatureMask(int mask);

Usage Examples

Lenient JSON Parsing

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

// Can now parse: {name: 'John', age: 30, /* comment */ active: true,}

Strict Parsing with Constraints

JsonFactory factory = JsonFactory.builder()
    .enable(StreamReadFeature.STRICT_DUPLICATE_DETECTION)
    .streamReadConstraints(StreamReadConstraints.builder()
        .maxStringLength(100_000)
        .maxNumberLength(100)
        .maxNestingDepth(50)
        .maxDocumentLength(1_000_000L)
        .build())
    .build();

Performance-Optimized Configuration

JsonFactory factory = JsonFactory.builder()
    .enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER)
    .enable(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER)
    .disable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION)
    .disable(JsonFactory.Feature.INTERN_FIELD_NAMES)
    .build();

Generator Configuration

JsonFactory factory = JsonFactory.builder()
    .enable(JsonWriteFeature.WRITE_BIGDECIMAL_AS_PLAIN)
    .disable(JsonWriteFeature.QUOTE_FIELD_NAMES) // Non-standard JSON
    .streamWriteConstraints(StreamWriteConstraints.builder()
        .maxNestingDepth(100)
        .build())
    .build();

Runtime Feature Toggle

JsonParser parser = factory.createParser(input);
parser.enable(StreamReadFeature.STRICT_DUPLICATE_DETECTION);

JsonGenerator generator = factory.createGenerator(output);
generator.disable(StreamWriteFeature.AUTO_CLOSE_JSON_CONTENT);

Feature Mask Operations

// Save current feature state
int originalMask = parser.getFeatureMask();

// Temporarily modify features
parser.enable(StreamReadFeature.IGNORE_UNDEFINED)
      .disable(StreamReadFeature.AUTO_CLOSE_SOURCE);

// Process with modified features
// ... parsing logic ...

// Restore original features
parser.setFeatureMask(originalMask);

Error Report Configuration

public final class ErrorReportConfiguration implements Serializable {
    public static final int DEFAULT_MAX_RAW_CONTENT_LENGTH = 500;
    public static final int DEFAULT_MAX_ERROR_TOKEN_LENGTH = 256;
    
    public static Builder builder();
    public static ErrorReportConfiguration defaults();
    
    public int getMaxRawContentLength();
    public int getMaxErrorTokenLength();
    
    public static class Builder {
        public Builder maxRawContentLength(int maxRawContentLength);
        public Builder maxErrorTokenLength(int maxErrorTokenLength);
        public ErrorReportConfiguration build();
    }
}

Example:

JsonFactory factory = JsonFactory.builder()
    .errorReportConfiguration(ErrorReportConfiguration.builder()
        .maxErrorTokenLength(100)
        .maxRawContentLength(200)
        .build())
    .build();

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