-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Decoding JSON to generic class #26
Comments
Hello, I've pushed changes to support your use-case. Plase note that this will probably not work on Web (I haven't tested, but I guess functions cannot cross Web Worker boundaries. Even if they could, you'd have to implement a marshaler so that your Please also note that it may also not work on all platforms -- it's a bit difficult to tell exactly what is sendable across 2 isolates. Some info is available from Dart's doc on isolates as well as the doc for send(). Publishing the update now! Regards |
The doc for send() also mentions bug http://dartbug.com/36983 / dart-lang/sdk#36983. This means if you provide a closure to the worker, it may end up capturing too many things. If this happens, maybe it can be worked around by passing a top-level function, or a static method / constructor tear-off (which is probably always preferable, anyways). |
Hey, I am trying to parse JSON string to dart object using
Model.fromJson
method inside a squadron worker.This should work fine for a given model class (not tested though).
But what I want to do is parse the JSON string to a generic dart object with something as:
Here, I can't pass
fromJson
method as an argument. It doesn't let the build runner pass withsquadron_builder
. Previously when I was usingdart:isolate
, I was able to pass this usingSendPort
.My use-case is more complicated than this, but I am stuck by this issue. One way to solve this is by returning the
Map<String, Object?>
and usefromJson
from main thread. However, since I am offloading my task, I wanted to parse the Json to dart object from the worker thread.The text was updated successfully, but these errors were encountered: