{"id":29867089,"url":"https://github.com/huangjiaqi0421/json_serializable_plus","last_synced_at":"2025-07-30T13:19:18.640Z","repository":{"id":56833399,"uuid":"323833890","full_name":"Huangjiaqi0421/json_serializable_plus","owner":"Huangjiaqi0421","description":"Generates utilities to aid in serializing from json","archived":false,"fork":false,"pushed_at":"2021-04-11T03:08:47.000Z","size":32,"stargazers_count":42,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-08-20T22:28:57.156Z","etag":null,"topics":["dart","dart-build-system","dartlang","flutter","json","json-annotation","json-serializable","source-gen"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Huangjiaqi0421.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-23T07:29:56.000Z","updated_at":"2023-03-12T06:43:52.000Z","dependencies_parsed_at":"2022-09-08T07:41:57.671Z","dependency_job_id":null,"html_url":"https://github.com/Huangjiaqi0421/json_serializable_plus","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"purl":"pkg:github/Huangjiaqi0421/json_serializable_plus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huangjiaqi0421%2Fjson_serializable_plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huangjiaqi0421%2Fjson_serializable_plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huangjiaqi0421%2Fjson_serializable_plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huangjiaqi0421%2Fjson_serializable_plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Huangjiaqi0421","download_url":"https://codeload.github.com/Huangjiaqi0421/json_serializable_plus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Huangjiaqi0421%2Fjson_serializable_plus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267874784,"owners_count":24158765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dart-build-system","dartlang","flutter","json","json-annotation","json-serializable","source-gen"],"created_at":"2025-07-30T13:19:16.945Z","updated_at":"2025-07-30T13:19:18.612Z","avatar_url":"https://github.com/Huangjiaqi0421.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json_serializable_plus\n\n使用build_runner，对官方json_serializable功能的增加，提供了统一的json解析方法。\n支持List解析。\n\n构建器会找到 [package：json_annotation](https://pub.dev/packages/json_annotation)注释的 类，生成统一的解析方法。\n\n查看[json_serializable](https://pub.dev/packages/json_serializable)的使用方法\n\n## Getting Started\n\n* 当前最新版本 json_serializable_plus: ^0.0.3\n\n在已经添加json_serializable 的基础上，只需要在`dev_dependencies`中添加`json_serializable_plus:^x.x.x` 。\n最终的`pubspec.yaml` 文件类似下面这样:\n```\ndependencies:\n  flutter:\n    sdk: flutter\n\n  json_annotation: '\u003e=3.1.0 \u003c3.2.0'\n\n\ndev_dependencies:\n  flutter_test:\n    sdk: flutter\n\n  build_runner: ^1.0.0\n  json_serializable: ^3.5.1\n  json_serializable_plus: ^0.0.3\n\n\n```\n## Example\n1. 给`Teacher` 和 `Student`设置 `@JsonSerializable()`注解\n\n```\nimport 'package:json_annotation/json_annotation.dart';\n\npart 'user.g.dart';\n@JsonSerializable()\nclass Teacher {\n  String teacherName;\n  int id;\n  List\u003cStudent\u003e students;\n  Teacher(this.teacherName,this.id,this.students);\n  factory Teacher.fromJson(Map\u003cString,dynamic\u003e json)=\u003e_$TeacherFromJson(json);\n}\n\n\n@JsonSerializable()\nclass Student {\n  String studentName;\n  int id;\n  Student(this.studentName,this.id);\n  factory Student.fromJson(Map\u003cString,dynamic\u003e json)=\u003e_$StudentFromJson(json);\n}\n\n\n```\n\n\n2. 运行`flutter pub run build_runner build`会在根目录会生成一个json_serializable.dart 文件\n\n3. 调用方法解析json\n\n```\nTeacher teacher = JsonSerializablePlus.fromJson(\n        json.decode(\"{\\\"teacherName\\\":\\\"hjq\\\",\\\"id\\\":32,\\\"students\\\":[{\\\"studentName\\\":\\\"s1\\\",\\\"id\\\":12},{\\\"studentName\\\":\\\"s2\\\",\\\"id\\\":12}]}\"));\n\n List\u003cStudent\u003e student = JsonSerializablePlus.fromJson(json.decode(\n        \"[{\\\"studentName\\\":\\\"s1\\\",\\\"id\\\":12},{\\\"studentName\\\":\\\"s2\\\",\\\"id\\\":12}]\"));\n```\n\n## TODO\n* 增加对json_annotation 字段的解析\n\n## QA\n\n* 运行`flutter pub run build_runner build`时出现\n\n```\nFailed to precompile build_runner:build_runner:\n../../../../../.pub-cache/hosted/pub.flutter-io.cn/build_resolvers-x.x.x/lib/src/resolver.dart:343:10: Error: Method not found: 'SummaryBuilder'.\nreturn SummaryBuilder(sdkSources, sdk.context)\n ```\n\n`dev_dependencies`指定`build_resolvers`版本 \u003e= `^1.5.1`\n\n\n* 运行`flutter pub run build_runner build`时出现`[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them.`\n\n代码提交时会把生成的*.g.dart提交上去，但是dart_tool/build 不会提交，所以在缺少dart_tool/build的文件情况下，flutter 无法自己删除重建。\n运行以下代码\n\n```\nflutter packages pub run build_runner clean\nflutter packages pub run build_runner build --delete-conflicting-outputs\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangjiaqi0421%2Fjson_serializable_plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuangjiaqi0421%2Fjson_serializable_plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangjiaqi0421%2Fjson_serializable_plus/lists"}