A custom implemenation of JSON to Dart model class from QuickType.
- https://dart-quicktype.netlify.app/
- https://dart-quicktype-2.netlify.app/
- https://dart-quicktype-3.netlify.app/
This project is configure to fit my use case only so the default behavior will be:
- All fields are final
- All fields are required
- Has an option to generate
toJSON
,copyWith
andtoString
- support
Equatable
andJsonSerialize
- No freezed or hive
When Dart class is generated from json, nullable or non-nullable field are define below.
Type | Nullable | default value |
---|---|---|
String | setting | "" |
bool | setting | false |
int | setting | 0 |
double | setting | 0 |
Array | never | [] |
Object | always | null |
DateTime | always | null |
- Array can never be null
- Object and DateTime always nullable
- Other types can configure with checkbox setting
- edit Dart's quicktype config in custom_dart_renderer.ts
- run npm run build to build from ts to vanilla js
- test your change in index.html