Skip to content

message_codes should explicitly support Map<String, dynamic> to better support JSON (Firebase) #833

Description

@kroikie

@kevmoo suggested i file an issue report here in regards to our discussion in this thread: google/json_serializable.dart#137

To summarize, Flutter's Firebase package returns documents from Firestore collections as _InternalLinkedHashMap<dynamic, dynamic>, but Flutter's recommended json package json_serializable expects json to come in as a Map<String, dynamic>. This results in the following error:

I/flutter ( 6352): type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' where
I/flutter ( 6352):   _InternalLinkedHashMap is from dart:collection
I/flutter ( 6352):   Map is from dart:core
I/flutter ( 6352):   String is from dart:core

Here is an example of some code which will trigger this:

_firestore = Firestore.instance;

return _firestore.collection('favorites').where('user_id', isEqualTo: uid).getDocuments()
				.then((querySnap) {
					querySnap.documents.forEach((document) {
						print(document.data);

						Map<String, dynamic> json = document.data; //casts, but if you put breaklines through this its that _InternalLinkedHashMap<dynamic, dynamic> type
						Album album = new Album.fromJson(json['favorite_albums'][0]); //Throws the type exception
					});
				})
				.catchError((error) {
					print(error);
				});

Thank you!

Activity

  1. kroikie commented on Oct 13, 2019

    @kroikie
    ContributorAuthor

    @jmrboosties

    The issue at flutter/flutter#17417 has been closed and moved here. Future collaboration on this issue will be done here.

  2. added
    impact: crowdAffects many people, though not necessarily a specific customer with an assigned label. (P2)
    on Oct 23, 2019
  3. kevmoo commented on Jan 23, 2020

    @kevmoo
    Contributor

    FYI: this isn't just about pkg:json_serializable – Dart's JSON logic deals with Map values as Map<String, dynamic> – it's also what folks expect

  4. Salakar commented on Jul 7, 2020

    @Salakar
    Contributor

    Hey all, as part of our on-going work for #2582, this has been resolved in our Firebase Firestore rework (#2913) - which has now been merged into master. We'll look at publishing some prereleases in the next few days. Thank you

  5. locked and limited conversation to collaborators on Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    impact: crowdAffects many people, though not necessarily a specific customer with an assigned label. (P2)plugin: cloud_firestoretype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions