|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Quick Start Commands |
| 6 | + |
| 7 | +### Building the Project |
| 8 | +```bash |
| 9 | +# Full build |
| 10 | +mvn clean compile |
| 11 | +mvn package |
| 12 | + |
| 13 | +# Build specific module |
| 14 | +mvn clean compile -pl json-java21 |
| 15 | +mvn package -pl json-java21 |
| 16 | + |
| 17 | +# Build with test skipping |
| 18 | +mvn clean compile -DskipTests |
| 19 | +``` |
| 20 | + |
| 21 | +### Running Tests |
| 22 | +```bash |
| 23 | +# Run all tests |
| 24 | +mvn test |
| 25 | + |
| 26 | +# Run tests with clean output (recommended) |
| 27 | +./mvn-test-no-boilerplate.sh |
| 28 | + |
| 29 | +# Run specific test class |
| 30 | +./mvn-test-no-boilerplate.sh -Dtest=JsonParserTests |
| 31 | +./mvn-test-no-boilerplate.sh -Dtest=JsonTypedUntypedTests |
| 32 | + |
| 33 | +# Run specific test method |
| 34 | +./mvn-test-no-boilerplate.sh -Dtest=JsonParserTests#testParseEmptyObject |
| 35 | + |
| 36 | +# Run tests in specific module |
| 37 | +./mvn-test-no-boilerplate.sh -pl json-java21-api-tracker -Dtest=ApiTrackerTest |
| 38 | +``` |
| 39 | + |
| 40 | +### JSON Compatibility Suite |
| 41 | +```bash |
| 42 | +# Build and run compatibility report |
| 43 | +./mvnw clean compile generate-test-resources -pl json-compatibility-suite |
| 44 | +./mvnw exec:java -pl json-compatibility-suite |
| 45 | + |
| 46 | +# Run JSON output (dogfoods the API) |
| 47 | +./mvnw exec:java -pl json-compatibility-suite -Dexec.args="--json" |
| 48 | +``` |
| 49 | + |
| 50 | +### Debug Logging |
| 51 | +```bash |
| 52 | +# Enable debug logging for specific test |
| 53 | +./mvn-test-no-boilerplate.sh -Dtest=JsonParserTests -Djava.util.logging.ConsoleHandler.level=FINER |
| 54 | +``` |
| 55 | + |
| 56 | +## Architecture Overview |
| 57 | + |
| 58 | +### Module Structure |
| 59 | +- **`json-java21`**: Core JSON API implementation (main library) |
| 60 | +- **`json-java21-api-tracker`**: API evolution tracking utilities |
| 61 | +- **`json-compatibility-suite`**: JSON Test Suite compatibility validation |
| 62 | + |
| 63 | +### Core Components |
| 64 | + |
| 65 | +#### Public API (jdk.sandbox.java.util.json) |
| 66 | +- **`Json`** - Static utility class for parsing/formatting/conversion |
| 67 | +- **`JsonValue`** - Sealed root interface for all JSON types |
| 68 | +- **`JsonObject`** - JSON objects (key-value pairs) |
| 69 | +- **`JsonArray`** - JSON arrays |
| 70 | +- **`JsonString`** - JSON strings |
| 71 | +- **`JsonNumber`** - JSON numbers |
| 72 | +- **`JsonBoolean`** - JSON booleans |
| 73 | +- **`JsonNull`** - JSON null |
| 74 | + |
| 75 | +#### Internal Implementation (jdk.sandbox.internal.util.json) |
| 76 | +- **`JsonParser`** - Recursive descent JSON parser |
| 77 | +- **`Json*Impl`** - Immutable implementations of JSON types |
| 78 | +- **`Utils`** - Internal utilities and factory methods |
| 79 | + |
| 80 | +### Design Patterns |
| 81 | +- **Algebraic Data Types**: Sealed interfaces with exhaustive pattern matching |
| 82 | +- **Immutable Value Objects**: All types are immutable and thread-safe |
| 83 | +- **Lazy Evaluation**: Strings/numbers store offsets until accessed |
| 84 | +- **Factory Pattern**: Static factory methods for construction |
| 85 | +- **Bridge Pattern**: Clean API/implementation separation |
| 86 | + |
| 87 | +## Key Development Practices |
| 88 | + |
| 89 | +### Testing Approach |
| 90 | +- **JUnit 5** with AssertJ for fluent assertions |
| 91 | +- **Test Organization**: |
| 92 | + - `JsonParserTests` - Parser-specific tests |
| 93 | + - `JsonTypedUntypedTests` - Conversion tests |
| 94 | + - `JsonRecordMappingTests` - Record mapping tests |
| 95 | + - `ReadmeDemoTests` - Documentation example validation |
| 96 | + |
| 97 | +### Code Style |
| 98 | +- **JEP 467 Documentation**: Use `///` triple-slash comments |
| 99 | +- **Immutable Design**: All public types are immutable |
| 100 | +- **Pattern Matching**: Use switch expressions with sealed types |
| 101 | +- **Null Safety**: Use `Objects.requireNonNull()` for public APIs |
| 102 | + |
| 103 | +### Performance Considerations |
| 104 | +- **Lazy String/Number Creation**: Values computed on demand |
| 105 | +- **Singleton Patterns**: Single instances for true/false/null |
| 106 | +- **Defensive Copies**: Immutable collections prevent external modification |
| 107 | +- **Efficient Parsing**: Character array processing with minimal allocations |
| 108 | + |
| 109 | +## Common Workflows |
| 110 | + |
| 111 | +### Adding New JSON Type Support |
| 112 | +1. Add interface extending `JsonValue` |
| 113 | +2. Add implementation in `jdk.sandbox.internal.util.json` |
| 114 | +3. Update `Json.fromUntyped()` and `Json.toUntyped()` |
| 115 | +4. Add parser support in `JsonParser` |
| 116 | +5. Add comprehensive tests |
| 117 | + |
| 118 | +### Debugging Parser Issues |
| 119 | +1. Enable `FINER` logging: `-Djava.util.logging.ConsoleHandler.level=FINER` |
| 120 | +2. Use `./mvn-test-no-boilerplate.sh` for clean output |
| 121 | +3. Focus on specific test: `-Dtest=JsonParserTests#testMethod` |
| 122 | +4. Check JSON Test Suite compatibility with compatibility suite |
| 123 | + |
| 124 | +### API Compatibility Testing |
| 125 | +1. Run compatibility suite: `./mvnw exec:java -pl json-compatibility-suite` |
| 126 | +2. Check for regressions in JSON parsing |
| 127 | +3. Validate against official JSON Test Suite |
| 128 | + |
| 129 | +## Module-Specific Details |
| 130 | + |
| 131 | +### json-java21 |
| 132 | +- **Main library** containing the core JSON API |
| 133 | +- **Maven coordinates**: `io.github.simbo1905.json:json-java21:0.1-SNAPSHOT` |
| 134 | +- **JDK requirement**: Java 21+ |
| 135 | + |
| 136 | +### json-compatibility-suite |
| 137 | +- **Downloads** JSON Test Suite from GitHub automatically |
| 138 | +- **Reports** 99.3% conformance with JSON standards |
| 139 | +- **Identifies** security vulnerabilities (StackOverflowError with deep nesting) |
| 140 | +- **Usage**: Educational/testing, not production-ready |
| 141 | + |
| 142 | +### json-java21-api-tracker |
| 143 | +- **Tracks** API evolution and compatibility |
| 144 | +- **Uses** Java 24 preview features (`--enable-preview`) |
| 145 | +- **Purpose**: Monitor upstream OpenJDK changes |
| 146 | + |
| 147 | +## Security Notes |
| 148 | +- **Stack exhaustion attacks**: Deep nesting can cause StackOverflowError |
| 149 | +- **API contract violations**: Malicious inputs may trigger undeclared exceptions |
| 150 | +- **Status**: Experimental/unstable API - not for production use |
| 151 | +- **Vulnerabilities**: Inherited from upstream OpenJDK sandbox implementation |
0 commit comments