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
type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast #351
Comments
Workaround: factory Chat.fromJson(Map<String, dynamic> json) {
json["members"] = (json['members'] as List)
?.map((e) =>
e == null ? null : Map<String, dynamic>.from(e))
?.toList();
return _$ChatFromJson(json);
} |
Duplicate of flutter/flutter#17417 – I'll try to take a look today... |
Actually, it looks like the map is coming from You can configure your generator to use Or change your map generation to create |
Tried any_map: true. But this didn't changed anything. Only working with the provided workaround. |
Glad you figured it out! |
@kevmoo Sorry, for the unclear answer. Setting any_map: true didn't change anything, this did not solved my problem. |
If the generated code didn't change at all, then you likely have something wrong with your configuration. |
I couldn't get any_map to work either. However, I tried |
neither In my case, I had a Map of another serializable object. My workaround in the
|
Running into this now. It's immediately apparent when trying to serialize JSON from firebase_database for some reason. |
None of these works. Print statement shows a map coming through. contentRef(schemaKey)
.child(entryId)
.once()
.then((snap) => Entry.fromJson(snap.value.cast<String, dynamic>())); contentRef(schemaKey)
.child(entryId)
.once()
.then((snap) => Entry.fromJson(Map.from(snap.value))); contentRef(schemaKey).child(entryId).once().then(
(snap) => Entry.fromJson(Map<String, dynamic>.from(snap.value))); using
|
See flutter/flutter#17417 – please add a 👍 there to encourage the flutter folks to run on it |
Thanks @kevmoo , I was able to move forward by using |
Only this was my solution
|
The best idea to Fix The Error |
When argument data pass through by MethodChannel or EventChannel. we should use codec JSONMethodCodec which will ensure type as Map<String, dynamic> automatically. |
I think the issue is related to
flutter/flutter#17417 (comment)
…On Wed, Jul 31, 2019 at 7:28 PM esonchen ***@***.***> wrote:
When argument data pass through by MethodChannel or EventChannel. we
should use codec *JSONMethodCodec* which will ensure type as Map<String,
dynamic> automatically.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#351>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAEFCTIAD62YE4G2HJRC23QCJC6JANCNFSM4F6HYP6A>
.
|
Thanks, I skipped this answer almost 10 times. You saved my life. Huge appreciate. 👍 |
This problem is still apparent and it's very annoying. If you try to unwrap any nested maps from Realtime Database it falls apart. Furthermore, the errors provided for some reason do not show stack into json_serializable, so it's very difficult to track down the source. |
firebase/flutterfire#833
Was this fixed? There's nothing to do here, sady...
…On Mon, Feb 22, 2021 at 6:19 PM Luke Pighetti ***@***.***> wrote:
This problem is still apparent and it's very annoying. If you try to
unwrap any maps from Realtime Database it falls apart.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#351 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEFCS5YW6R3Q72FNLDJD3TAMGBJANCNFSM4F6HYP6A>
.
|
Just for the sake of my understanding, is there any reason why I suspect I'm going to have to make a visitor to mutate nested maps into |
If I edit the As implemented _$_FBList _$_$_FBListFromJson(Map<String, dynamic> json) {
return _$_FBList(
info: json['info'] == null
? null
: FBListInfo.fromJson(json['info'] as Map<String, dynamic>),
members: (json['members'] as Map<String, dynamic>)?.map(
(k, e) => MapEntry(k,
e == null ? null : FBListMember.fromJson(e as Map<String, dynamic>)),
),
items: (json['items'] as Map<String, dynamic>)?.map(
(k, e) => MapEntry(
k, e == null ? null : FBListItem.fromJson(e as Map<String, dynamic>)),
),
);
} Change to allow toJson to work with realtime database response objects. _$_FBList _$_$_FBListFromJson(Map<String, dynamic> json) {
return _$_FBList(
info: json['info'] == null
? null
: FBListInfo.fromJson(json['info'] as Map<String, dynamic>),
members: (json['members'] as Map<String, dynamic>)?.map(
(k, e) => MapEntry(
k,
e == null
? null
: FBListMember.fromJson(Map<String, dynamic>.from(e))),
),
items: (json['items'] as Map<String, dynamic>)?.map(
(k, e) => MapEntry(k,
e == null ? null : FBListItem.fromJson(Map<String, dynamic>.from(e))),
),
);
} |
I was able to get it to work with a combination of things
But I am still curious to hear your thoughts about the solution in my previous comment. |
Yeah The problem w/ your proposal is it copies data unnecessarily. I guess we could do a |
I'm going to consider this resolved, thanks for the reply. |
thanks bro |
create UserData class then pass data without the <String, dynamic> The data after fetching should be the same cast it to map without the <String, dynamic> |
I get following error, when i want to deserialize an object with a property of type List<> containing another serializeable object. If i change "ChatMember.fromJson(e as Map<String, dynamic>)" to "Map<String, dynamic>.from(e)" everything works perfect. Can you fix this, is there any workaround possible so i can continue my work?
The text was updated successfully, but these errors were encountered: