Closed heronlyj closed 3 years ago
@heronlyj Hi.
Thank you for your report. I see you use json_serializable
and I wonder have you same issues without json_serializable
?
@iamarnas Hi.
If json_serializable
is not referenced, thexxx.g.dart
file will not be generated 😅
@heronlyj Hi. Thank you for your report. I see you use
json_serializable
and I wonder have you same issues withoutjson_serializable
?
@iamarnas Hi.
If don't use freezed
, the result is the same, I mentioned the same issuse in
@heronlyj Hi.
If json_serializable is not referenced, the xxx.g.dart file will not be generated 😅
I meant that Json Serializable
is false
in your models.jsonc
Ok. Your generated JSON with Json to Dart Model
looks as expected.
class Course {
int type;
String name;
String img;
int id;
List<CourseNode> courseNode;
Course({
this.type,
this.name,
this.img,
this.id,
this.courseNode,
});
factory Course.fromJson(Map<String, dynamic> json) {
return Course(
type: json['type'] as int,
name: json['name'] as String,
img: json['img'] as String,
id: json['id'] as int,
courseNode: (json['courseNode'] as List<dynamic>)
?.map((e) => e == null
? null
: CourseNode.fromJson(e as Map<String, dynamic>))
?.toList(),
);
}
Map<String, dynamic> toJson() {
return {
'type': type,
'name': name,
'img': img,
'id': id,
'courseNode': courseNode?.map((e) => e?.toJson())?.toList(),
};
}
}
When you use Freezed
or Json Serializable
then Json to Dart Model
generates only types and everything that happens after Json Serializable
takes care of the rest and is responsible for generated code. Even Freezed
depends on Json Serializable
. If Json Serializable
fails then the Freezed
fails too.
So that in that case Json to Dart Model
more accurate than Json Serializable
:sunglasses: and I can do nothing here need wait for a fix from the Json Serializable
developers and no reason to keep these issues opened.
But thanks to you @heronlyj I found where I missed syntax correction :smiley: From now on, generated code will be cleaner.
The data type is the following
part of
models.jsonc
file:Then the generated dart file looks like this (the
toJson
part)But the correct toJson code should look like this
flutter doctor
vscode extension version:
v3.1.1