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

NoSuchMethodError (NoSuchMethodError: Class '[AnyType]' has no instance getter 'toJSON'. #15

Open
mrasityilmaz opened this issue Dec 13, 2024 · 1 comment

Comments

@mrasityilmaz
Copy link

NoSuchMethodError: Class '_Map<String, Object>' has no instance getter 'toJson' in socket.io usage with EVENT type packets

Description

I am encountering a NoSuchMethodError with the following details:
This error occurs when I receive packets of type EVENT while using socket_io_client. To resolve this, I updated the package version from 3.0.0-beta.2 to 3.0.2 as I saw a similar issue addressed in socket_io_common. However, the issue persists in the latest version as well.

The problem seems to be related to a missing toJson method in the Map implementation. The issue likely stems from how packets are being handled or parsed within the socket library.

Steps to Reproduce

  1. Use the socket_io_client package version 3.0.2.
  2. Establish a socket connection to a server.
  3. Receive a packet of type EVENT.
  4. Observe the following error in the logs:
NoSuchMethodError: Class_Map<String, Object>’ has no instance getter ‘toJson’.
Receiver: _Map
Tried calling: toJson
---
NoSuchMethodError (NoSuchMethodError: Class '_Map<String, Object>' has no instance getter 'toJson'.
Receiver: _Map len:4
Tried calling: toJson)
---
NoSuchMethodError (NoSuchMethodError: Class 'int' has no instance getter 'toJSON'.
Receiver: 2
Tried calling: toJSON)
---
NoSuchMethodError (NoSuchMethodError: Class 'String' has no instance getter 'toJSON'.
Receiver: "exitRoom"
Tried calling: toJSON)
---
NoSuchMethodError (NoSuchMethodError: Class 'List<dynamic>' has no instance getter 'toJSON'.
Receiver: Instance(length:2) of '_GrowableList'
Tried calling: toJSON)

Environment

  • Package: socket_io_client 3.0.2
  • Dart/Flutter version: 3.5.4 - Dart SDK / 3.24.4 - Flutter SDK
  • Platform: IOS

Expected Behavior

The library should correctly handle or parse EVENT type packets without throwing a NoSuchMethodError. Ideally, any _Map object should be deserialized properly or handled internally.

Actual Behavior

The application throws a NoSuchMethodError when a toJson method is called on _Map<String, Object> during the handling of an EVENT type packet.

Attachments

  • A screenshot of the error is attached.

Ekran Resmi 2024-12-13 19 21 20

Example Code Snippet

socket.emit('eventName','StringValue');
@jumperchen
Copy link
Member

The implementation should ignore this error: is_binary.dart. However, I don't know why Flutter throws that error. A few weeks ago, a user encountered a similar error, and after cleaning their Flutter environment, the error disappeared.

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

No branches or pull requests

2 participants