Can Backendless save a polymoprhed list of objects in one table?

Can a list of subclassed objects (extended from a common parent) be saved in one table? For example, an Animal table could contain a Dog that extends an Animal class and a Cat that extends the Animal class.

I have attempted this and I get BackendlessException{ code: ‘1022’, message: 'All related objects for a property must be of the same type. …} I am hoping it is something I am overlooking.

Thank you!

Hi Carol,

It would be possible if you can “normalize” your polymorphed objects to HashMaps. There is API which we recently introduced that does not require you to have a strongly-typed classes on the client side. It works the same way as the data service API, but operates on java.util.Map objects. For example, the following method:

Backendless.Data.of( “Animal” ).find( asyncCallcack );

will bring a collection (BackendlessCollection) of Map objects. Each map represents a record in the table. If you have a special column which identifies a specific type (for example, “animalKind”), then you would be able to have a factory on the client side to materialize any given map into an object of a specific class.

Hope this helps.

Mark