schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
153 stars 23 forks source link

Can not use Isolate.run with the mapper class #189

Closed devfelipereis closed 5 months ago

devfelipereis commented 5 months ago

Hello!

I have a code like this:

SomeMapper.fromMap(data)

It works fine but now it is heavy and I was trying to move it to an isolate. Like this:

Isolate.run(() => SomeMapper.fromMap(data) )

The problem is that it doesn't work. It throws a MapperException that it can not resolve a type (Cannot resolve type from property "XX". Invalid or unregistered type). But without the Isolate, it works fine.

Do you have any idea why this is happening?

schultek commented 5 months ago

Any calls to initializeMappers() or SomeMapper.ensureInitialized() need to be repeated since isolates don't have shared global memory.

devfelipereis commented 5 months ago

Oh yeah. Thank you!