zorphy_annotation 1.3.1 copy "zorphy_annotation: ^1.3.1" to clipboard
zorphy_annotation: ^1.3.1 copied to clipboard

Annotations for zorphy code generation package that provides clean class definitions with copyWith, JSON serialization, toString, equality, and inheritance support

example/README.md

Zorphy Annotation Examples #

This directory contains comprehensive examples demonstrating how to use the zorphy_annotation package with the zorphy code generator.

Prerequisites #

Before running these examples, ensure you have the following dependencies installed:

dart pub get

Running Code Generation #

After making changes to any entity file, run the code generator:

dart run build_runner build

To automatically rebuild when files change:

dart run build_runner watch

To clean generated files before rebuilding:

dart run build_runner build --delete-conflicting-outputs

Example Files #

basic_example.dart #

Demonstrates basic entity creation with:

  • Simple entity definition
  • Required and optional fields
  • copyWith functionality
  • Equality and toString
  • Patch operations

json_example.dart #

Shows JSON serialization capabilities:

  • toJson() and fromJson() methods
  • Lean JSON (excluding metadata fields)
  • Complex object serialization

sealed_class_example.dart #

Illustrates sealed class hierarchies:

  • Polymorphic types
  • Type-safe discriminators
  • Exhaustiveness checking

nested_example.dart #

Demonstrates nested object support:

  • Nested entity composition
  • Nested patching
  • Tree structures

generic_example.dart #

Shows generic type parameter support:

  • Generic entities
  • Type safety with generics
  • Reusable data structures

enum_example.dart #

Shows enum field integration:

  • Enum fields in entities
  • JSON serialization with enums
  • Pattern matching

Running the Examples #

After generating code, you can run the main example file:

dart run lib/basic_example.dart
dart run lib/json_example.dart
dart run lib/sealed_class_example.dart
dart run lib/nested_example.dart
dart run lib/generic_example.dart
dart run lib/enum_example.dart

Generated Code #

When you run the code generator, Zorphy creates .zorphy.dart files alongside your entity files. These generated files contain:

  • Concrete class implementations
  • Constructors
  • copyWith methods
  • Patch classes for partial updates
  • JSON serialization (when enabled)
  • Equality operators
  • toString methods
  • Comparison methods (when enabled)

Note: Never edit the generated .zorphy.dart files directly, as they will be overwritten on the next build.

Learning More #

For complete documentation, visit:

0
likes
0
points
1.91k
downloads

Publisher

verified publisherzuzu.dev

Weekly Downloads

Annotations for zorphy code generation package that provides clean class definitions with copyWith, JSON serialization, toString, equality, and inheritance support

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, dartx, json_annotation, quiver

More

Packages that depend on zorphy_annotation