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

Model could not be deserialized #266

Closed aminelaadhari closed 7 years ago

aminelaadhari commented 7 years ago

Hi, When a model class implementing Serializable is deserialized, all the properties are null. Is there any reason why deserialization is not working for generated model classes?

I can't use parcels. Thanks !

sbosley commented 7 years ago

@aminelaadhari model objects are not serializable using the Java Serializable interface, because the ValuesStorage objects they use to hold property values are in turn not serializable. You can however make model objects implement Parcelable, by using the androidModels code generation option documented on this wiki page. You can also see an example of declaring this option in our test project. Hope that helps!

aminelaadhari commented 7 years ago

Thanks @sbosley but in my current context I can't make objects implement Parcelable. Do you think of another solution?

sbosley commented 7 years ago

@aminelaadhari the only other thing I can think of is to use a code generation plugin to alter the generated model's superclass to a custom superclass that implements the serializable interface correctly. We do this for parcelable using classes like AndroidTableModel -- it creates a specialized ContentValuesStorage object for holding model values that implements parcelable, so that the model's values can be written to and read from parcels. You might be able to do something similar for serializable.

Can I ask why parcelables are unavailable to you? Do you need to serialize objects to disk outside of a SQLite database for some reason?

sbosley commented 7 years ago

@aminelaadhari also, if you'd like faster support, you can join our gitter chat. It's generally a better channel for this kind of support than GitHub issues.

aminelaadhari commented 7 years ago

Will try your suggestion, thanks!