feat: Support json serializable (closes #377)#410
Conversation
2395fa4 to
0dd7d1c
Compare
| final calculateListenVariables = jsonWidgetListenVariables == null; | ||
| final resultListenVariables = jsonWidgetListenVariables ?? <String>{}; | ||
| final processedMapArg = {}; | ||
| final processedMapArg = <String, dynamic>{}; |
There was a problem hiding this comment.
Does the processMapArg need support other types than String as key? If so we could make this parser generic.
String is required by serialization parsing (as json only supports String as key).
WalkthroughThis PR adds support for parsing entities annotated with Changes
Sequence DiagramsequenceDiagram
participant CodeGen as Code Generator
participant Decoder as Decoder
participant Analyzer as Type Analyzer
participant Generated as Generated Code
CodeGen->>Analyzer: Analyze class/enum type
Analyzer->>Analyzer: Check for fromJson factory
Analyzer-->>Decoder: Return type with fromJson
alt parseJsonSerializable enabled
Decoder->>Decoder: Detect ClassElement/EnumElement<br/>with fromJson
Decoder->>Generated: Generate Class.fromJson(map['field'])
Generated-->>Decoder: Decoded value
else parseJsonSerializable disabled
Decoder->>Decoder: Use existing decoder<br/>or default value
Decoder-->>Generated: Fallback behavior
end
Generated-->>CodeGen: Return decoded object
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (11)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (12)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Sorry for the late review. I'd been heads down in a new code generator for json_theme and only now found time to notice this. Just updated the PR to resolve the conflicts. I'll test it later and if it still works, merge it. |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
packages/codegen/CHANGELOG.md(1 hunks)packages/codegen/lib/builder.dart(1 hunks)packages/codegen/lib/src/builder/json_widget_library_builder.dart(2 hunks)packages/codegen/lib/src/decoder/decoders.dart(4 hunks)packages/codegen/pubspec.yaml(1 hunks)packages/json_dynamic_widget/README.md(2 hunks)packages/json_dynamic_widget/example/build.yaml(1 hunks)packages/json_dynamic_widget/example/lib/src/components/example_registrar.dart(1 hunks)packages/json_dynamic_widget/example/lib/src/json_serializable/person.dart(1 hunks)packages/json_dynamic_widget/example/lib/src/json_serializable/team_builder.dart(1 hunks)packages/json_dynamic_widget/example/lib/src/json_serializable/team_widget.dart(1 hunks)packages/json_dynamic_widget/example/pubspec.yaml(2 hunks)packages/json_dynamic_widget/lib/src/components/processors/map_arg_processor.dart(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (12)
packages/codegen/pubspec.yaml (1)
4-4: LGTM! Version bump aligns with feature addition.The minor version bump from 4.0.0+1 to 4.1.0 correctly reflects the addition of the new parseJsonSerializable feature.
packages/json_dynamic_widget/example/build.yaml (1)
1-6: LGTM! Configuration enables the new feature.The build configuration correctly enables
parse_json_serializablefor the example project to demonstrate the new JsonSerializable parsing capability.packages/json_dynamic_widget/example/pubspec.yaml (2)
17-17: LGTM! Adds required dependency for JsonSerializable support.The
json_annotationdependency is necessary for using@JsonSerializableannotations in example code.
31-31: LGTM! Codegen version update matches the new feature.The update to
^4.1.0aligns with the codegen package version bump that introduces parseJsonSerializable support.packages/json_dynamic_widget/README.md (2)
31-31: LGTM! TOC updated with new feature section.The table of contents correctly includes the new "Parse JsonSerializable Entities" section.
754-768: LGTM! Clear documentation for the new feature.The documentation provides clear instructions on:
- When to use the feature (entities with @JsonSerializable or custom fromJson)
- How to enable it (build.yaml configuration)
- Links to the relevant package
packages/json_dynamic_widget/lib/src/components/processors/map_arg_processor.dart (3)
27-27: LGTM! Improved type safety.The narrowed type constraint to
Map<String, dynamic>is appropriate for JSON parsing, where keys are always strings.
35-38: LGTM! Consistent type constraints throughout.The explicit
Map<String, dynamic>types ensure type safety and align with JSON parsing semantics where keys are always strings.
90-90: LGTM! Parameter type aligns with usage.The
Map<String, dynamic>parameter type is consistent with the narrowed type constraints and reflects JSON structure.packages/codegen/lib/src/builder/json_widget_library_builder.dart (2)
17-23: LGTM! Well-documented public API addition.The new
parseJsonSerializableparameter:
- Has a sensible default (false) maintaining backward compatibility
- Is clearly documented with a reference to json_serializable
- Enables the new feature as intended
880-887: LGTM! Feature flag properly threaded through decoder.The
parseJsonSerializableflag is correctly passed to thedecode()function, enabling the new JsonSerializable parsing behavior when requested.packages/json_dynamic_widget/example/lib/src/components/example_registrar.dart (1)
7-7: Generated file is not in repository; import usage cannot be verified automatically.The generated file
example_registrar.g.dartis not present in the repository (it's built into.dart_tool/at build time and typically not committed). The import on line 7 has no direct references in the source code, but the@jsonWidgetRegistrarcode generator likely needs theteam_builder.dartimport to register_TeamBuilderas a JSON widget builder.Verify one of the following:
- Run
dart run build_runner buildin the example directory and inspectbuild/or.dart_tool/output to confirm_TeamBuilderis referenced in the generated code- Check the
json_dynamic_widgetgenerator documentation to understand how@jsonWidgetRegistrarprocesses builder imports- If the import is confirmed as unused after generation, remove both the import and the
unused_importignore directive
# Conflicts: # examples/json_dynamic_widget_example/build.yaml # examples/json_dynamic_widget_example/lib/src/json_serializable/person.dart # examples/json_dynamic_widget_example/lib/src/json_serializable/team_builder.dart # examples/json_dynamic_widget_example/lib/src/json_serializable/team_widget.dart # packages/codegen/CHANGELOG.md # packages/codegen/pubspec.yaml # packages/json_dynamic_widget/README.md # packages/json_dynamic_widget/example/pubspec.yaml
|
@jpeiffer I updated the PR to the recent changes of |
Description
Closes #377
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyzeordart analyze) does not report any problems on my PR. Note: analyze fails to incompatibility with 3.35.xpubspec.yamlwith an appropriate new version according to the pub versioning philosophy.CHANGELOG.mdto add a description of the change.UI Change
Does your PR affect any UI screens?
Summary by CodeRabbit
Release Notes
New Features
@JsonSerializable()annotation and customfromJsonmethods, enabling seamless integration with json_serializable patterns.Documentation
Examples
✏️ Tip: You can customize this high-level summary in your review settings.