charcoal 0.0.5
charcoal: ^0.0.5 copied to clipboard
Unified annotation for generating ultra-fast JSON, copy, equals, hash code, and toString, with the type graph resolved at build time.
charcoal
A highly opinionated Dart build_runner with a unified annotation. Generates JSON, copy, equality, hash and toString as direct code for any annotated data class, with the whole type graph resolved at build time: no registry, no runtime lookup, nor dynamic dispatch. Configurations (and errors) are checked at build time.
The main goal of this project is to be a blazingly fast, static alternative to dart_mappable, which is itself a sane alternative to Google's json_serializable.
Install #
dart pub add charcoal dev:charcoal_builder dev:build_runner
Usage #
import 'package:charcoal/charcoal.dart';
part 'book.charcoal.g.dart';
@immutable
@Charcoal()
class Book({
required this.id,
required this.title,
required this.genres,
this.notes,
this.releasedAt,
}) with BookCharcoal {
final Id<Book> id;
final String title;
final List<Genre> genres;
final String? notes;
final DateTime? releasedAt;
}
final book = BookCharcoal.fromJsonString(body);
final revised = book.copyWith(notes: null);
final json = revised.toJsonString();
Generate the code with dart run build_runner build, which you can add to your build script.
Contributing #
See our CONTRIBUTING guide.