Core Jackson processing abstractions (aka Streaming API), implementation for JSON
—
JsonFactory serves as the central factory for creating JsonParser and JsonGenerator instances. It provides thread-safe, reusable configuration for JSON processing with extensive customization options.
public static JsonFactoryBuilder builder() {
return new JsonFactoryBuilder();
}
public static class JsonFactoryBuilder extends TSFBuilder<JsonFactory, JsonFactoryBuilder> {
public JsonFactoryBuilder enable(JsonFactory.Feature f);
public JsonFactoryBuilder disable(JsonFactory.Feature f);
public JsonFactoryBuilder enable(StreamReadFeature f);
public JsonFactoryBuilder disable(StreamReadFeature f);
public JsonFactoryBuilder enable(StreamWriteFeature f);
public JsonFactoryBuilder disable(StreamWriteFeature f);
public JsonFactoryBuilder streamReadConstraints(StreamReadConstraints src);
public JsonFactoryBuilder streamWriteConstraints(StreamWriteConstraints swc);
public JsonFactoryBuilder errorReportConfiguration(ErrorReportConfiguration erc);
public JsonFactory build();
}public JsonFactory() {
this((ObjectCodec) null);
}
public JsonFactory(ObjectCodec codec) {
this(codec, DEFAULT_FACTORY_FEATURE_FLAGS);
}public JsonParser createParser(String content) throws IOException;
public JsonParser createParser(InputStream in) throws IOException;
public JsonParser createParser(Reader r) throws IOException;
public JsonParser createParser(byte[] data) throws IOException;
public JsonParser createParser(byte[] data, int offset, int len) throws IOException;
public JsonParser createParser(File f) throws IOException;
public JsonParser createParser(URL url) throws IOException;
public JsonParser createParser(DataInput in) throws IOException;public JsonGenerator createGenerator(OutputStream out) throws IOException;
public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException;
public JsonGenerator createGenerator(Writer w) throws IOException;
public JsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException;
public JsonGenerator createGenerator(DataOutput out) throws IOException;public enum Feature implements JacksonFeature {
// Symbol handling
INTERN_FIELD_NAMES(true),
CANONICALIZE_FIELD_NAMES(true),
FAIL_ON_SYMBOL_HASH_OVERFLOW(true),
// Parser features
USE_FAST_DOUBLE_PARSER(true),
USE_FAST_BIG_NUMBER_PARSER(true),
// Generator features
USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING(true);
public boolean enabledByDefault();
public boolean enabledIn(int flags);
public int getMask();
}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();
}
}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();
}
}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();
}
}JsonFactory factory = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
.disable(JsonFactory.Feature.INTERN_FIELD_NAMES)
.build();JsonFactory factory = JsonFactory.builder()
.streamReadConstraints(StreamReadConstraints.builder()
.maxStringLength(1_000_000)
.maxNumberLength(100)
.maxNestingDepth(500)
.build())
.streamWriteConstraints(StreamWriteConstraints.builder()
.maxNestingDepth(500)
.build())
.build();JsonFactory factory = JsonFactory.builder()
.errorReportConfiguration(ErrorReportConfiguration.builder()
.maxErrorTokenLength(200)
.maxRawContentLength(1000)
.build())
.build();JsonFactory factory = new JsonFactory();
factory.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS);
factory.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);JsonFactory instances are thread-safe once configured and can be reused across multiple threads. Configuration should be done before sharing the factory instance between threads.
Jackson Core uses buffer recycling for improved performance. The factory manages buffer pools through the BufferRecycler system, which can be configured through factory features.
public BufferRecycler _getBufferRecycler();
public void _releaseBuffers(BufferRecycler recycler);Install with Tessl CLI
npx tessl i tessl/maven-com-fasterxml-jackson-core--jackson-core