Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Map type #97

Open
princ3od opened this issue Aug 25, 2022 · 6 comments
Open

Support Map type #97

princ3od opened this issue Aug 25, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@princ3od
Copy link

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.

@iamarnas
Copy link
Collaborator

iamarnas commented Aug 25, 2022

@princ3od Hi 👋 Thanks for suggestion.
I wonder you mean MapView?

Example:

class Person extends MapView<StringString> { 
   final String firstName; 
   final String lastName; 
   Person(this.firstName, this.lastName) 
       : super( 
           { 
             'first_name': firstName, 
             'last_name': lastName, 
           }, 
         ); 
 }

source

@iamarnas iamarnas added the enhancement New feature or request label Aug 25, 2022
@princ3od
Copy link
Author

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.

@iamarnas
Copy link
Collaborator

@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.

@princ3od
Copy link
Author

princ3od commented Aug 26, 2022

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.

@iamarnas
Copy link
Collaborator

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.

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

@clivi-kj
Copy link

also looking for this. would be helpful for Firestore conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants