yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Question: is it possible to make the TableModelSpec annotation to add Serializable/Parcelable support? #148

Closed AndroidDeveloperLB closed 8 years ago

AndroidDeveloperLB commented 8 years ago

I tried adding this:

...@Implements(interfaceClasses = {Serializable.class})

And the new entity did add its own :

...extends TableModel implements Serializable {

But when I tried using it, I've found that all of the fields are null. Looking deeper, this seems to be because the fields data are in a map.

Is it possible to make the entities classes implement Serializable/Parcelable ?

sbosley commented 8 years ago

All model objects already implement Parcelable, so you should be good to go!

Note that if you are using our dev_3.0 branch, you will need to specify an option in the apt config in your build.gradle for this to be the case:

apt {
    arguments {
        squidbOptions 'androidModels'
    }
}
AndroidDeveloperLB commented 8 years ago

If this is true, how come I don't see the generated model implement this interface, and also not any of the classes it extends/implements?

We use version 3. Is it because of this? but where do you put this code you've written?

sbosley commented 8 years ago

Yes, if you are using version 3, you will need to add the apt configuration I mentioned to your build.gradle in order for the generated models to implement Parcelable. I think we've already determined that your gradle setup is different from ours :) so YMMV, but in our gradle files, this configuration just goes right below the dependencies.

AndroidDeveloperLB commented 8 years ago

OK, thank you for your quick help.

AndroidDeveloperLB commented 8 years ago

It seems to work great. What's the reason that on v3 we have to add the extra instructions to the gradle file, while for v2 we don't?

sbosley commented 8 years ago

The main feature in v3 is support for iOS via Google's j2objc tool, which means that in v3 all dependencies on Android classes were removed from the core SquiDB module -- including Parcelable. In v2 models implemented Parcelable by default because the project was Android-only. The squidb-android addon module in v3 contains all the necessary support code for model objects to implement Parcelable when running on Android, and the gradle instructions simply activate that option in the code generator.

AndroidDeveloperLB commented 8 years ago

I see. Thank you. You are great.

sbosley commented 8 years ago

Happy to help!