Support Topics Documentation Slack YouTube Blog

UpdateListener of the real time DB doesn't return Point value

Hello!

I got an issue when executing the following code:
The “my_table” contains a column of the type “Point”;

EventHandler MyEventHandler= Backendless.Data.of( “my_table” ).rt();
DriversAround.addUpdateListener(whereClause_, new AsyncCallback() {
@Override
public void handleResponse(Map response) {

              Point my_point = (Point)response.get("location");

// the above line produce fatel exception: *java.util.HashMap cannot be cast to com.backendless.persistence.Point
//While if I execute the above line in find function (without using updateListener) then it works
}

                    @Override
                    public void handleFault(BackendlessFault fault) {

                    }
                });

Tell me, please,
How can I get the Point object correctly inside the UpdateListener -> handleResponse function?

Hi @Maria_Kudriashova!

Interface com.backendless.rt.data.EventHandler is generified. It means that it can work with different types. In your case by calling Backendless.Data.of( “my_table” ).rt(); you receive EventHandler<Map>. This instance will pass to registered callbacks data using java.util.Map objects. All relations data also will be placed in instances of java.util.Map.

For working with instances of entity classes you must use next code for retrieving EventHandler: Backendless.Data.of([your entity class].class).rt(). In this case your callback will receive entity instead of map.

Also I strongly recommend you to use generics in your code. With them you can avoid such problems.

Regards, Andriy