-
Notifications
You must be signed in to change notification settings - Fork 408
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
When get List<T> Hive V4 throws 'Type Mismatch' error #1302
Comments
Resolving Type Mismatch Error in Hive with Generic ModelsThe error "Invalid argument(s): Type mismatch. Expected UserCacheModel but got CorporationCacheModel." typically occurs when there's a mix-up with how adapters are registered or how Hive boxes are opened with specific types. This issue is often related to improper handling of type registrations or incorrect usage of Hive's box and adapter mechanisms, especially when dealing with generic models and mixins. Root Cause of the IssueThe problem arises because the adapters for different types ( Solution Implemented in the PRIn the pull request #1310 , the issue has been resolved by ensuring that each Key Changes in the PR:
How to Use the SolutionTo use the fixed version of Hive with your generic models, follow these steps:
Make sure your HiveCacheManager is set up as follows to initialize and register the adapters properly:
Ensure that each operation on your cache models, like getAll, correctly references the unique adapters registered for those models:
Note By following these steps and using the changes implemented in the PR, you should be able to resolve the type mismatch error and use the getAll function correctly with your generic models in Hive. If you encounter further issues, ensure that each model's adapter is correctly registered and that no adapters are overridden during initialization. Warning For the solution to work correctly, ensure to clean the Hive cache once initially using Hive.deleteAllBoxesFromDisk() before registering the adapters. This step helps to avoid type conflicts from previously cached data. Tip And hey, if you'd like to buy me a coffee, your code might just run even better! 😉 |
I have tried to make module from Hive with Generic models. Created 'CacheModel' mixin like this:
And a manager to registerAdapters like this:
CacheManager is an abstract class and have a CacheOperation abstract class like this:
I also have a HiveCacheOperation which extends CacheOperation of T Type like this:
I created a UserCacheModel and extend it from CacheModel like this:
Finally created a ProductCache which required CacheManager like this:
But when i try to call .getAll function of userCacheOperation i got "Invalid argument(s): Type mismatch. Expected UserCacheModel but got CorporationCacheModel.".
So is this a registerAdapter error or something else?
The text was updated successfully, but these errors were encountered: