json_model
json_model copied to clipboard
Generate model class from Json file. 一行命令,通过Json文件生成Dart Model类。
例如 user_entity.json 生成的 dart 类,类名应该是 UserEntity 而不是 User_entity,这样是不符合 dart 语法规范的,并且 AS 直接就警告语法有问题。 json 数据中的字段名转换规则应该也是一样的,例如键名 user_name 应该转换为 userName,而不是保持原名。 求大佬更新支持以上两个特性,不然每次运行命令生成文件都要自己手动改名字,而且因为每次运行命令都是重新生成文件,所以之前改好的文件还需要备份,再替换新文件,反而比使用其他插件手动生成 dart 类麻烦更多。
And because mobx_codegen >=0.1.3 depends on build ^1.1.4 and mobx_codegen >=0.4.2 depends on build_resolvers ^1.3.2, mobx_codegen >=0.4.2 requires build ^1.2.0. And because json_model 0.0.2 depends on build >=1.0.0 0.0.2 =0.4.2...
经常碰到这个错误,有时候卡半天,有人碰到过吗? ```You have hit a bug in build_runner Please file an issue with reproduction steps at https://github.com/dart-lang/build/issues type 'DynamicTypeImpl' is not a subtype of type 'InterfaceType' package:analyzer/src/summary/link.dart 5535:5 TypeProviderForLink._buildInterfaceType package:analyzer/src/summary/link.dart...
枚举,以及自定义fromJson,toJson
The method 'cleanFor' isn't defined for the class 'CleanCommand'. - 'CleanCommand' is from 'file:///Users/canday/.pub-cache/hosted/pub.flutter-io.cn/json_model-0.0.2/bin/src/commands/clean.dart'. Try correcting the name to the name of an existing method, or defining a method named...
下面这段是我使用json_model后,遇到的一些问题,我大约有100+个的json文件,下面这段是是写在我们项目里面的,也粘贴到这里来,希望对大家能有帮助 ## Model自动生成注意事项 - Model自动生成使用了[json_model](https://github.com/flutterchina/json_model "json_model"),使用他的主要原因是:他使用了[json_serializable](https://pub.dartlang.org/packages/json_serializable "json_serializable"),性能比较好,另外他需要自建一个jsons目录,将需要处理的json文件放到这个目录,除了生成model后,还有"备份"的效果,方便后续检查问题,例如经常会出现的搞不清楚到底是json数组,还是json对象,有了这个"备份",后面就很好定位问题 - 使用:vscode->终端->项目根目录 执行 flutter packages pub run json_model 命令 将jsons目录下的文件生成对应的model - 因为 json_model 现在还有一些小的bug(大多和生成后import错误相关),所以需要手里处理一些和import相关的bug - 将生成完并确认没有问题的json文件名前面增加 "_", 避免下次执行 flutter packages pub run json_model...

分别被限制成了2.0.0和1.0.0了。可以更新下吗
``` { "@JsonKey(name: 'firebase_auth') firebaseAuth": "$[]firebaseAuth" } ``` creates: ``` @JsonKey(name: 'firebase_auth') firebaseAuth $[]firebaseAuth; ``` expected: ``` @JsonKey(name: 'firebase_auth') List firebaseAuth; ```