dart_json_annotations 2.2.0
dart_json_annotations: ^2.2.0 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.2.0 #
Breaking Changes #
- API Simplified: Removed preset constructors (
@Model.json(),@Model.data(), etc.) in favor of explicit parameters for better clarity and flexibility. - Improved @Ignore: Changed
@Ignoresyntax to use named parameters (e.g.,@Ignore(json: true)) instead of deprecated factory constructors. - Default Extension: Changed default generated file extension from
.gen.dartto.t.dart.
New Features #
- Comprehensive Union Support: Improved support for all parameter combinations in union variants (no params, positional, named, mixed).
- Unused Variable Fix: Parameterless union variants now use
_in generated pattern matching to avoidunused_local_variablewarnings. - Mutable Support: Added
mutableparameter to@Modelfor classes with non-final fields.
2.1.0 #
New Features #
- Nullable Serialization Control:
- Nullable fields are now included by default in
toJson(asnull). - Added
@JsonKey(ignoreIfNull: true)(orignoreJsonIfNull: true) to opt-out and skip fields if they are null. - Added
includeIfNullparameter toJsonKey(defaults totrue).
- Nullable fields are now included by default in
- Global Activation Fix: Improved package root resolution so the CLI works correctly when activated globally or run from any directory.
Bug Fixes #
- Fixed "Target not found" error when running
dart_json_genin a new project.
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