refactor: migrate to json_serializable-based toJson and mixin toString#5
Merged
Conversation
…r FIDO2 entities and requests
…serialization examples
There was a problem hiding this comment.
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.
Harry-Chen
approved these changes
Sep 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.