-
Notifications
You must be signed in to change notification settings - Fork 6
refactor: migrate to json_serializable-based toJson and mixin toString #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…r FIDO2 entities and requests
…serialization examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the codebase to use json_serializable for automatic toJson generation and introduces a JsonToStringMixin for consistent toString behavior across entities and requests. It replaces manual toString implementations with JSON-based serialization while maintaining the same logging/debugging functionality.
- Migrates 20+ classes to use @JsonSerializable annotations with automatic toJson generation
- Introduces JsonToStringMixin that provides toString() via jsonEncode(toJson())
- Adds CI workflow validation to ensure generated code stays in sync
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pubspec.yaml | Adds json_annotation, json_serializable, and build_runner dependencies |
| lib/src/utils/serialization.dart | Introduces JsonToStringMixin for consistent JSON-based toString |
| Generated .g.dart files | Auto-generated toJson factory functions for annotated classes |
| CTAP2 entities and requests | Converts manual toString to JsonSerializable + JsonToStringMixin |
| Server entities | Migrates server-side data classes to use json_serializable |
| lib/src/cose.dart | Updates CoseKey with custom toJson due to MapView inheritance |
| lib/src/ctap.dart | Converts CtapResponse and CtapError to use new serialization pattern |
| .github/workflows/test.yml | Adds build_runner validation to CI |
| example/json_serializable_example.dart | Demonstrates new serialization capabilities |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Current Progress
Implementing json_serializable + JsonToStringMixin for core/ctap2 and src/server entities and requests:
dart run build_runner buildcheck.Special Cases
Two classes remain with manual toJson implementation:
CoseKey: extends MapView<int, dynamic>, json_serializable incompatible. Manual toJson handles numeric key conversion.CtapError: extendsError, inherited StackTrace causes generation issues. Simple manual toJson for status + name.