SnackJson is a Java JSON processing library that provides three primary capabilities: JSON DOM manipulation through the ONode abstraction, JSONPath query execution, and JSON Schema generation and validation. The framework is organized as a multi-module Maven project with a core module (snack4) and two extension modules (snack4-jsonpath, snack4-jsonschema). snack4-parent/pom.xml50-54
The central design principle is that all JSON data is represented internally as ONode trees—a universal node type inspired by JavaScript's unified variable declaration (var) and XML DOM's node abstraction. Everything underneath it is represented by an ONode, which stands for "One node" and can be converted to any type. README.md51-52
Scope: This page provides a technical overview of SnackJson's architecture, module dependencies, core abstractions, and extension mechanisms. For detailed information on specific subsystems:
ONode type system and APIs: ONode Data ModelSnackJson is structured as three independent Maven modules under the snack4-parent parent POM. Each module can be used independently or in combination: snack4-parent/pom.xml56-74
| Module | Maven Coordinates | Purpose |
|---|---|---|
| snack4 | org.noear:snack4 | Core JSON DOM building and codec support README.md62 |
| snack4-jsonpath | org.noear:snack4-jsonpath | JSONPath query support README.md63 |
| snack4-jsonschema | org.noear:snack4-jsonschema | JSON Schema validation and generation support README.md64 |
Module Dependency Graph
The core module (snack4) has a mandatory dependency on eggg for advanced type introspection and reflection capabilities. snack4/pom.xml20-24 The project maintains a Java 1.8 baseline. snack4-parent/pom.xml41
Sources: snack4-parent/pom.xml41-74 snack4/pom.xml19-32 snack4-jsonpath/pom.xml20-25 snack4-jsonschema/pom.xml20-31 README.md60-64
The ONode class is the universal JSON node representation that underlies all SnackJson operations. Every JSON value—whether object, array, or primitive—is represented as an ONode instance. README.md51-52
ONode Data Flow Architecture
All conversions between JSON strings, Java objects, and schemas flow through ONode as the intermediate representation, enabling uniform handling of JSON data regardless of source or destination format. README.md51-52
Sources: README.md51-52 UPDATE_LOG.md200-207
JsonReader parses JSON text into ONode trees, while JsonWriter serializes them back to strings. The framework supports streaming operations via readNext(), readLast(), and iterableNext() for efficient processing of large datasets without loading the entire structure into memory. UPDATE_LOG.md38-41
The codec system uses BeanEncoder and BeanDecoder to bridge Java objects and ONode. It prioritizes no-argument constructors and field-based codecs to reduce injection risks. README.md57 Customization is provided via the CodecLib registry, which manages encoders, decoders, and creators. UPDATE_LOG.md68
The snack4-jsonpath module provides a high-performance query engine. It is compatible with both jayway.jsonpath and the IETF JSONPath (RFC 9535) standard. README.md54 Users can switch between standards using Options. README.md54
snack4-jsonschema provides construction and validation of JSON schemas, compatible with Draft-07 and Draft-2019 standards. README.md55 It supports annotation-driven metadata via ONodeAttr and default value generation. UPDATE_LOG.md34 snack4/src/main/java/org/noear/snack4/annotation/ONodeAttr.java61
Sources: README.md53-57 UPDATE_LOG.md34-41 UPDATE_LOG.md200-207
The Options class serves as the central configuration hub, allowing users to toggle Feature flags and register custom logic. UPDATE_LOG.md67
Extension Registry Architecture
Features control specific behaviors, such as Feature.Read_AutoRepair for fixing malformed JSON UPDATE_LOG.md13 or Feature.Write_BigDecimalAsPlain for numeric formatting. UPDATE_LOG.md182 Feature flags can be managed at the Options level or locally via the ONodeAttr annotation. snack4/src/main/java/org/noear/snack4/annotation/ONodeAttr.java81
The @ONodeAttr annotation allows for property-level configuration, including aliasing (name), requirement status (required), and custom format patterns. snack4/src/main/java/org/noear/snack4/annotation/ONodeAttr.java35-107 It also supports specifying custom encoder and decoder classes directly on fields or methods. snack4/src/main/java/org/noear/snack4/annotation/ONodeAttr.java101-106 Metadata is processed and stored in ONodeAttrHolder. snack4/src/main/java/org/noear/snack4/annotation/ONodeAttrHolder.java36
Sources: snack4/src/main/java/org/noear/snack4/annotation/ONodeAttr.java35-107 snack4/src/main/java/org/noear/snack4/annotation/ONodeAttrHolder.java36-133 UPDATE_LOG.md13-182 UPDATE_LOG.md67-70
Sources: snack4-parent/pom.xml1-48 README.md1-43
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.