Error cashing HASHMAP to LIST when returning relation


I am trying to load relation using

Backendless.Data.of(GlobalVar.TABLES.ROOM.TABLE_NAME).find(queryBuilder, new AsyncCallback<List<Map>>() {

The Room table has a column called “availabilities”. It has 1:N relation. I expect that i should be able to iterate over the relations as follow

List<Map> avail_list_temp =( List<Map>) map.get(GlobalVar.TABLES.ROOM.AVAILABILITY);
But I am getting the following error (the return relation has one relation for that entry though)
java.lang.ClassCastException: java.util.HashMap[] cannot be cast to java.util.List

Shouldn’t it be a list<map> with one entry?



Do you request the “availabilities” column to be included into the response in your queryBuilder?


In the request I set the depth to be 2 so yes it is included.
Even when I debug I see that it is included and that hasmap[] is returned. I thought it should be list<Map>


When you retrieve data using the “dictionary” approach, related objects come back as an array of Map objects. However, if you were to use the class-based approach, then you can control the collection type of the returned relations by declaring them either as List or an array.


Ohh hmm. Is that a change to exiting behaviour? Last app I made 5 months ago returned it as list of maps using the same “depth” approach so I just copied-paste the code to the new app

When you say class based approach, do you mean the one step and 2 step retrieval approach? Or are these also dictionary approaches.

I am just going by the docs here :slight_smile:

No, I do not think that has changed. That’s how it had been for version 4.

As for the approaches, they are documented right there in the doc:;/img&gt;;/img&gt;

As you can see above, this is under the 1 step retrieval of relationship (and it is under Java Map). It shows the the AsyncCallBack receives the relations as List<Map>. So I assumed it is the same for the relationship depth. However it seems it gets the relations as an array of map.

Anyways if the array of Map is the expected behaviour then I will change the code to handle that. I just wanted to ensure that I am not missing something here

PS: I think reflecting that in docs would help as I don’t think it says anywhere that related entries are returned as HashMap (except in the Users Table property under special consideration).

This has always been the default behaviour of our Android SDK: the higher-level collections are cast to java.util.List (thus you receive a List<Map> for find() and loadRelations() calls), but the inner fields remain Map arrays (so the parent.get( “childs” ) etc. returns Map[]).

We’re adding these details to the documentation, too. Thank you for mentioning this issue.