How fasterxml/jackson-core works
Project type and purpose
• This is an open‑source Java library (“jackson‑core”) providing low‑level streaming abstractions for parsing and generating data (JSON by default, but extensible to other formats).
• It defines core interfaces (JsonFactory, JsonParser, JsonGenerator, TokenStreamFactory, ObjectCodec, TreeCodec) and default JSON implementations, on which higher‑level data binding (jackson‑databind) and alternative format modules (Smile, XML, CSV, YAML, Protobuf, CBOR) build.
File structure
• Top‑level build/config scripts: pom.xml, mvnw(.cmd), release scripts, GitHub Actions workflows.
• src/main/java/com/fasterxml/jackson/core: core API and abstractions (Factory, Parser/Generator base classes, IO, filtering, format detection, utilities, versioning).
• src/main/java/com/fasterxml/jackson/core/json and json/async: default JSON parser/generator implementations and non‑blocking I/O.
• src/main/resources/META‑INF/services: ServiceLoader entry point for pluggable JsonFactory.
• moditect and site: JPMS module descriptor and documentation site config.
• docs: packaged Javadoc for multiple versions.
• src/test: extensive unit and fuzz tests covering every package.
README for additional insights
• Core abstraction vs JSON‑specific separation.
• No runtime dependencies (JUnit only for testing).
• Usage pattern: clients obtain a reusable JsonFactory (builder pattern), then create JsonParser/JsonGenerator.
• Extensibility via ServiceLoader for alternate formats.
Main components and relationships (to appear
a. Client Layer
– Application code or jackson‑databind’s ObjectMapper calls JsonFactory (builder) → JsonParser/JsonGenerator.
b. Core Abstractions Module
– TokenStreamFactory, JsonFactory, JsonFactoryBuilder, JsonParser/JsonGenerator interfaces, ObjectCodec, TreeCodec, JsonStreamContext, JsonToken.
– StreamReadFeature/StreamWriteFeature, FormatFeature, StreamReadConstraints/StreamWriteConstraints, ErrorReportConfiguration.
c. JSON Implementation Module
– JSON‑specific parser/generator: ByteSourceJsonBootstrapper, ReaderBasedJsonParser, UTF8JsonGenerator, JsonGeneratorImpl, NonBlockingUtf8JsonParser, FilteringParserDelegate/FilteringGeneratorDelegate.
d. I/O & Utility Module
– IOContext, InputDecorator/OutputDecorator, ByteArrayFeeder/ByteBufferFeeder, BufferRecycler, TextBuffer, DataOutputAsStream, JsonStringEncoder.
e. Extensibility/Plugin Points
– META‑INF/services entry for JsonFactory, DataFormatDetector/DataFormatMatcher for autodetecting format.
– Other format modules implement the same interfaces and register via ServiceLoader.
f. Test & Fuzzing Suite (optional to show as separate module)
Architectural patterns and design principles
• Factory & Builder patterns: JsonFactoryBuilder → JsonFactory → Parser/Generator.
• Decorator pattern: InputDecorator/OutputDecorator wraps raw inputs/outputs.
• Delegation pattern: FilteringParserDelegate, FilteringGeneratorDelegate extend core parser/generator behavior.
• Strategy/ServiceLoader: pluggable JsonFactory implementations for various formats.
• Modular layering: core abstractions <— JSON implementation <— format‑specific modules <— data binding.
Elements
• Module/Package clusters with clear labels.
• Notes on patterns (e.g., “Factory”), and ServiceLoader for plugin discovery.