Repository navigation
message_codes should explicitly support Map<String, dynamic> to better support JSON (Firebase) #17417
Description
Activity
It is a bug, in the meantime, you can use something like this
If you have nested Map, well, you will have to manually modify the .g.dart file to replace
casts byMap<String, dynamic>.from()Reacted by Pablo Soto González- You can also use the latest json_serializable with the `any_map` option set to true! See the readme…On Thu, May 31, 2018 at 6:12 AM Serge B ***@***.***> wrote: It is a bug, in the meantime, you can use something like this <#16589> If you have nested Map, well, you will have to manually modify the .g.dart file to replace casts by Map<String, dynamic>.from() — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#17417 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AABCinXTFSvii8ZxxdxMnTUVSRHH7Wj2ks5t3-xagaJpZM4T3zuc> .Reacted by Serge B, Sam Carlile and chaoxiang wen
Wow, took me ages to find how to use this... I had to create a build.yaml.
Any other way ? the documentation is not clear on how to use this flag with the command line.
Thanksbuild.yaml with this content should be good. Did you try that?
targets: $default: builders: json_serializable: options: any_map: true
Reacted by JosueReacted by Marcelino Borges, Vamsi Krishna, hey_its_sean, Lee Ouf and anegreteI did, and it worked, my question was : how to pass the anyMap parameter without using a build.yaml (ie in the command line)
We do support a
--defineflag which is a bit verbose but would look something like this:--define "json_serializable=any_map=true"Reacted by Serge B, Abdullah Al Asad and CruorVultReacted by Brent Williams- addedc: crashStack traces logged to the consoleStack traces logged to the consolep: firebaseObsolete - Firebase pluginsObsolete - Firebase plugins
on Jun 12, 2018 jaguar_serializer is also affected by this issue @tejainece
For jaguar_serializer this was fixed right now
jaguar_serializer: 2.1.5 jaguar_serializer_cli. 2.1.14
Reacted by Ravi Teja Gudapati and Subrahmanya S MSetting any_map to true didn't work for me. Any tips?
Currently using a workaround found here: #15007As said better use jaguar_serializer with Firebase
Reacted by Ravi Teja Gudapati@stavangr – are you getting the same errors? Have you upgraded the flutter plugin to latest?
26 remaining items
Hey guys!
I've struggling so much these days trying to get this json stuff working.
The sad part of it is that I remember using Firebase with native android framework (java) and things used to be so simple and easy, no need of json... And with Flutter we have to struggle like this to parse to/from json all the time, and there is always a problem showing up. =(Just to let you know... the build.yaml has worked for me.
And do not forget to execute the flutter pub run build_runner build in the terminal before trying again!
My exception:
Unhandled Exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' in type castflutter doctor:
`Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Microsoft Windows [versão 10.0.17763.615], locale pt-BR)[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[√] Android Studio (version 3.3)
[!] IntelliJ IDEA Community Edition (version 2019.1)
X Flutter plugin not installed; this adds Flutter specific functionality.
[!] VS Code (version 1.35.0)
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)! Doctor found issues in 2 categories.
`got this problem now also. Is there any fix?
Got this same exception just now coming from code generated by JsonSerializable
Unhandled Exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' in type castCurrently using:
- iOS Simulator
- Flutter 1.9.5 channel dev
- JsonSerializable v 3.2.2
I have identified that it is because of inner Maps. Root map converts just fine.
Has any solutions come up yet?
UPDATE
Adding parameter anyMap:true to all JsonSerializable constructors that included inner maps and works fine. As mentioned above, this seems to be a workaround and not a fixed, so will continue waiting for a fix.
This is frustrating, like a lot of developers my test project with Flutter is porting an established Android/iOS app that uses Firebase, at this point I hit a brick wall when trying to serialise some simple Json:
var remoteConfig = await config.fetchRemoteConfig(); var configUrls = remoteConfig.getString("configUrls"); print("Config urls: " + configUrls); var configUrlsJson = json.decode(configUrls);[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'Guys, please check again flutter oficial docs about json serializable (https://flutter.dev/docs/development/data-and-backend/json). I've made a pull request recently and it was already merged.
Look for the nested classes section, there are a few tricks worth to be tried. There is the "anyMap: true" trick and a bit more. Check it out and see if it works for you.
As a new Flutter dev the path for lots of people is the above, everything is smooth then they hit this issue when they try and work with Json - workarounds aren't the point. After being stuck for a few of hours, going away and coming back to it again I found:
Map<String, dynamic> configUrlsJson = jsonDecode(configUrlsString);- seems obvious now, but not to a noob in Flutter/Dart.It might not seem a big issue for seasoned Dart devs but orientating in a new language and framework takes time,
anyMap: truesounds so simple, but then they have to find out where to put that, build.yaml right? Cool, so where does that live? More research, then you have to run another command to rebuild withflutter pub run build_runner build- all of this for a new Dart/Flutter developer is bewildering. The issue is I believe over a year old, and it's tripping a lot of people up:json.decodeshould just work.Reacted by Jose Tapizquent, wreyford, Peter Galkaev, Felipe Bueno, João Rafael Mendes Nogueira, Laura Meckley, anegrete, Sebastian Engel, ChrisWF, Ashutosh Singh and 12 moreReacted by Ashutosh Singh and iTikozThis issue has been moved to firebase/flutterfire#833. Any further collaboration will be done there.
Wow, took me ages to find how to use this... I had to create a build.yaml.
Any other way ? the documentation is not clear on how to use this flag with the command line.
Thanksafter doing this, don't forget to
flutter pub run build_runner build --delete-conflicting-outputsThis thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Aug 15, 2021 - addedpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
on Jul 5, 2023
@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:
Here is an example of some code which will trigger this:
Thank you!