wilinz / json5_model

A one-line command to convert a JSON file into a Dart model class.
https://pub.dev/packages/json5_model
MIT License
11 stars 1 forks source link

不兼容json_model库的官方写法 #2

Open dev-xdyang opened 10 months ago

dev-xdyang commented 10 months ago

按照json_model pud官方网页的写法,编译出的model dart文件报错。看到文档说@meta不兼容,但 age? 这种写法也不兼容吗?不确定是特性,还是bug.

{
    "@JsonKey(name: '+1') int?": "loved",
    "name": "wendux",
    "keywords": "$[]String",
    "age?": 20
}
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

name: github_client_app
description: "A new Flutter project."
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: '>=3.2.2 <4.0.0'

# flutter pub upgrade --major-versions
# flutter pub outdated
dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2

  # json model map
  json_annotation: ^4.8.1

  shared_preferences: ^2.2.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
  build_runner: ^2.4.7

  # json model map
  json_serializable: ^6.7.1
  # dart run json5_model --src=r/json --dist=lib/models --once=false
  json5_model: ^2.0.3
  # dart run json_model --src=r/json --dist=lib/models
  # json_model: ^1.0.0
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.2, on macOS 14.1 23B74 darwin-arm64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.84.2)
wilinz commented 10 months ago

现在推荐的做法是生成 dart 文件后再修改 dart 代码,json 只是作为数据结构参考文件,支持在 json 文件里标记的话实现过于复杂,目前没有这样的计划