dart_json_annotations 2.0.1
dart_json_annotations: ^2.0.1 copied to clipboard
High-performance code generation for Dart/Flutter: JSON, copyWith, equatable, and union/sealed class support. Rust-powered CLI with parallel processing.
Changelog #
2.0.1 #
New Features #
- Configurable file extensions: Support for
dart_json_gen.yamlto customize generated file extensions (e.g.,.t.dart,.g.dart). - Flexible Cleanup: The
--cleancommand now accepts paths to specific files or directories for targeted deletion of generated files. - Improved Config Loading: Automatic configuration discovery by searching parent directories upwards from the input path.
Bug Fixes #
- Removed unreachable
_ => throw StateErrorcase in generatedtoJsonmethods for sealed classes, resolving Dart analyzer warnings. - Fixed thread-safety issues in parallel processing for CLI operations.
Improvements #
- Enhanced verbose output with more detailed parsing and generation logs.
- Better error handling for missing input paths.
2.0.0 #
Breaking Changes #
- Unified
@Modelannotation replaces@Json,@CopyWith,@Equatable,@DataClass - Removed legacy annotations (still work but deprecated)
- Changed default behavior: Use
@Model.json()for JSON-only generation
New Features #
-
Preset constructors for common patterns:
@Model.json()- JSON only (~25 lines)@Model.data()- JSON + copyWith + equatable (~50 lines)@Model.bloc()- copyWith + equatable, no JSON (~35 lines)@Model.full()- All features (~70 lines)@Model.mutable()- Mutable classes with copyWith (~40 lines)
-
Sealed/Union class support:
when()- Exhaustive pattern matchingmaybeWhen()- Optional pattern matching with orElsewhenOrNull()- Nullable pattern matchingmap()- Type-based mappingmaybeMap()- Optional type mapping- Type checkers:
isSuccess,isFailure, etc. - Safe casts:
asSuccess,asFailure, etc.
-
@Ignoreannotation with variants:@Ignore()- Ignore from all features@Ignore.json()- Ignore from JSON only@Ignore.equality()- Ignore from == comparison@Ignore.copyWith()- Ignore from copyWith
-
Parallel processing using Rust's rayon crate (3-4x faster)
-
Compact output - Optimized for large codebases (200+ models)
-
--threadsoption to control parallelism
Performance #
- 70% smaller output size with
@Model.json()preset - File-level shared helpers instead of per-class
- Lazy regex compilation
- Pre-allocated string buffers