fluttercandies / JsonToDart

The tool to convert json to dart code, support Windows,Mac,Web.
MIT License
355 stars 42 forks source link

add smart nullable #10

Closed simonkimi closed 3 years ago

simonkimi commented 3 years ago

在开启空安全后, value为null的字段将会默认勾选可空 可以直接解析List类型的Json了, 字段为取并集 对部分有setter但没有使用setter进行修改

zmtzawqlp commented 3 years ago

it seems that smart nullable is better than auto nullable

zmtzawqlp commented 3 years ago

run dartfmt -w . before you push pr

simonkimi commented 3 years ago

done

simonkimi commented 3 years ago

修改说明:

  1. DartObject_jObject由原先的Map<String, dynamic>修改为Map<String, Tuple3<dynamic, DartType, bool>>, Tuple3中分别为 数据/类型/是否可空, 记录类型可在DartObject.merge中对类型进行对比并去除Null, 此举是为解决形如[{"foo": null}, {"foo": 123}]的foo类型被解析为Object?
  2. 对于List<dynamic>的Json解析被改为为List添加一个头ArrayRoot, 将List转换为Map<List<dynamic>>进行解析, 随后去除ArrayRoot节点, 将depth整体减一. 此举可对列表查空的逻辑进行复用.
zmtzawqlp commented 3 years ago

LGTM, thanks for your contribution