Skip to main content

charcoal 0.0.1 copy "charcoal: ^0.0.1" to clipboard
charcoal: ^0.0.1 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 #

ci

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.g.dart';

@immutable
@Charcoal()
class Book({
  required this.id,
  required this.title,
  required this.genres,
  this.note,
  this.releasedAt,
}) with BookCharcoal {
  final Id<Book> id;
  final String title;
  final List<Genre> genres;
  final String? note;
  final DateTime? releasedAt;
}
final book = BookCharcoal.fromJsonString(body);
final revised = book.copyWith(note: 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.

1
likes
0
points
1.27k
downloads

Publisher

unverified uploader

Weekly Downloads

Unified annotation for generating ultra-fast JSON, copy, equals, hash code, and toString, with the type graph resolved at build time.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on charcoal