RuntimeException from Backendless.Persistence.save: GeoPoint cannot be cast to java.util.Map

I got an error during persist data to Backendless. It happens randomly after a week without problems.

Server.Processing, java.lang.RuntimeException: java.lang.ClassCastException: com.backendless.geo.model.GeoPoint cannot be cast to java.util.Map

Hi Martin,

Could you please show the code which makes the API call resulting in that error?

Mark

public void func() {
	
	// device object received from Backendless, just make an update


	GeoPoint location = device.getLocation();
	if (location == null) {
		// not location set yet, create location object first
		location = new GeoPoint();
		location.addCategory("Senior");
	}


	location.setLatitude(ping.getLatitude());
	location.setLongitude(ping.getLongitude());
	location.setMetadata(meta);


	persist(location, new IResultGeoCallback() {
		@Override
		public void response(final GeoPoint geoPoint) {


			// geo location is persisted, so persist also the device object
			persist(device, new IResultSeniorCallback() {
				@Override
				public void response(SeniorTracking data) {


					// so create relation between saved object and geo location
					relation(device, geoPoint);
				}


				@Override
				public void fault(String code, String message) {
					logger.error("Could not create relation between data and geo location");
				}
			});
		}


		@Override
		public void fault(String code, String message) {
			logger.error("Could not persist ping update due to location update failed! Backendless server reported an error code=" + code + ", msg=" + message);
		}
	});
}




private static void persist(final SeniorTracking device, final IResultCallback callback) {
	// Asynchronous - persist lost request into remote Crowd GPS Service
	Backendless.Persistence.save(device, new AsyncCallback<SeniorTracking>() {
		@Override
		public void handleResponse(SeniorTracking response) {
			// new LostDevice instance has been saved
			logger.debug("Device " + response.getImei() + " has been saved to Backendless. Remote object id=" + response.getObjectId());


			if (callback != null) {
				callback.response(response);
			}
		}


		@Override
		public void handleFault(BackendlessFault fault) {
			// an error has occurred
			logger.error("Could not persist data for IMEI=" + device.getImei() + "! Backendless Server reported an error code=" + fault.getCode() + ", " + fault.getMessage());


			if (callback != null) {
				callback.fault(fault.getCode(), fault.getMessage());
			}
		}
	});
}

See the code, it fails on line 60 when trying to porsist/save device object. This code works perfectly more than week until now. Backendless return an error.

Line 60 is when an error already happened. Which of the calls caused the error?

Also, are you using the latest Backendless SDK for Android?

I use SDK 4.0.3, line 21. cause the persist error. Thank you.

Hi Martin,

I can’t see any obvious reasons for the error looking at your code. If you could prepare a minimal verifiable sample so that we could run it and reproduce the error, it would be of much help in finding a solution quickly. Otherwise we’ll try to investigate it by creating some samples to reproduce, but be aware that this won’t be a top priority task and might take some time.

Hi Mark, any idea what is going wrong? The exception came from the server. Thank you.

Hi Sergey, the problem is with GEO Point relation. The question is how to work with data object with location relation? I use relation location:GeoPoint:1.

How do I create my map object?

Version 1)

public class DataObject {
...
 private GeoPoint location;
 ...
}

Version 2) Use the Collection also for 1:1 relation?

public class DataObject {
...
 private List<GeoPoint> location;
 ...
}

For 1-to-1 relations use version 1 (single object field), for 1-to-many relations use version 2 (collection field).

You can also download the example classes for your data schema from the Code Generation tab.

The collection is not working, it did not get any data from server when there is relation 1:1. So when I use version 1) i got the exception during DataObject save() when the location is not null (location object exist from previous get() ).

Any Idea what’s wrong?

This is the reason why I got exception from server

java.lang.ClassCastException: com.backendless.geo.model.GeoPoint cannot be cast to java.util.Map

Hi Sergey, i just check my code also with iOS SDK. I found the same error on iPhone. When my data object has a relation 1:1 to location and also this data object have assignet location object (location is not null), then it fails on save operation with server error. I will appreciate any help to solve this issue because it has a negative impact on my app customers. Thank you.

Backendless Server reported an error: Optional(FAULT = 'Server.Processing' [java.lang.RuntimeException: java.lang.ClassCastException: com.backendless.geo.model.GeoPoint cannot be cast to java.util.Map] <java.lang.RuntimeException: java.lang.ClassCastException: com.backendless.geo.model.GeoPoint cannot be cast to java.util.Map> )

I prepared a testing project to reproduce the server exception. Just run the java main method.

BackendlessTest.zip (30.43kB)

Thank you Martin, we’ll look into it and get back to you here as soon as we have any news.

I was able to reproduce the problem. The internal task BKNDLSS-16260 has been created to investigate this further.

Thank you Sergey!
Where I can see progress or estimation on this issue? It is blocker issue for my customer in pilot project and they are a little bit nervous :slight_smile:

First, you should change your code to save relation using Relation API, this is a change we’ve introduced in Backendless version 4: https://backendless.com/docs/android/doc.html#related_objects
As a temporary workaround for the problem described above, you should set the “location” field to null before saving, In the meantime we’re going to fix the exception when saving the entity with related GeoPoint set, but be aware that the point won’t be saved along with the parent object and will just be ignored.

Sergey, thank you for your support and effort I appreciate that.

  1. yes I used the new relation API, it works fine
  2. yes I used this temporary workaround, it is OK for now.

Please let me know when wou solve the issue on server.

Sure. It may take a few days till the permanent fix will be available on server and in main branch SDK. We shall notify you here as soon as it is solved.

Hi Martin

We’ve made a fix for correct error handling. Currently the object will be saved but without a relation to a geo point as Sergey has already described above. Please verify

Best regards