Skip to content

Commit

Permalink
Add freezed JSON serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
satvikpendem authored Jan 10, 2025
1 parent 6efec58 commit 0af55e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ impl EnumRefApiDartGenerator<'_> {
};
let maybe_implements_exception =
generate_dart_maybe_implements_exception(self.mir.is_exception);
let json_serde = format!(
"factory {name}.fromJson(Map<String, dynamic> json) => _${name}FromJson(json);",
);

Some(ApiDartGeneratedClass {
namespace: src.name.namespace.clone(),
Expand All @@ -47,6 +50,8 @@ impl EnumRefApiDartGenerator<'_> {
{variants}
{json_serde}
{extra_body}
}}",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ fn generate_end_api_text(
import: "import 'package:freezed_annotation/freezed_annotation.dart' hide protected;"
.into(),
part: format!(
"part '{name}.freezed.dart';",
"
part '{name}.freezed.dart';
part '{name}.g.dart';
",
name = dart_output_path.file_stem().unwrap().to_str().unwrap()
),
..Default::default()
Expand Down

0 comments on commit 0af55e5

Please sign in to comment.