Open princ3od opened 2 years ago
Thanks for replying @iamarnas. But I mean I have a json as show below
{
"__className": "Topic",
"id": "sport",
"is_stored": true,
"name": "Sport",
"articles.Map": {}
}
My expected output will be
import 'package:freezed_annotation/freezed_annotation.dart';
part 'topic.freezed.dart';
part 'topic.g.dart';
@freezed
class Topic with _$Topic {
factory Topic({
String? id,
String? name,
@JsonKey(name: 'is_stored') bool? isStored,
Map articles,
}) = _Topic;
factory Topic.fromJson(Map<String, dynamic> json) => _$TopicFromJson(json);
}
And the Map type should be Map class of Dart. Currently, it will create a new class called Map.
@princ3od In this way "articles.Map": { ... }
you force rename object type with this generator, but it just not work with primitive values. Have you tried it? I don't remember if Map
is allowed. By using Freezed it would be possible to allow it.
I tried it and it did not work. So how can I generate a class with a Map
type field? I see List
type field is already supported.
I tried it and it did not work. So how can I generate a class with a
Map
type field? I seeList
type field is already supported.
If it doesn't work then it's not allowed. List
supported becouse it generates with this generator but Map
not. Need to implement.
@princ3od
also looking for this. would be helpful for Firestore conversions.
It would be great if
Json-to-Dart-Model
supported Map data type as it already supported List. Currrently, if the key is something like"key.Map":{}
, it creates a whole new class called Map. I think it should use the existed Map class of Dart. Thank you.