Backendless Support
 
Solved

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.

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

Best Answer
photo

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

Leave a Comment

Comments (20)

photo
1

Hi Martin,

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

Mark

photo
1

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.

photo
photo
1

  1. public void func() {
  2. // device object received from Backendless, just make an update
  3. GeoPoint location = device.getLocation();
  4. if (location == null) {
  5. // not location set yet, create location object first
  6. location = new GeoPoint();
  7. location.addCategory("Senior");
  8. }
  9. location.setLatitude(ping.getLatitude());
  10. location.setLongitude(ping.getLongitude());
  11. location.setMetadata(meta);
  12. persist(location, new IResultGeoCallback() {
  13. @Override
  14. public void response(final GeoPoint geoPoint) {
  15. // geo location is persisted, so persist also the device object
  16. persist(device, new IResultSeniorCallback() {
  17. @Override
  18. public void response(SeniorTracking data) {
  19. // so create relation between saved object and geo location
  20. relation(device, geoPoint);
  21. }
  22. @Override
  23. public void fault(String code, String message) {
  24. logger.error("Could not create relation between data and geo location");
  25. }
  26. });
  27. }
  28. @Override
  29. public void fault(String code, String message) {
  30. logger.error("Could not persist ping update due to location update failed! Backendless server reported an error code=" + code + ", msg=" + message);
  31. }
  32. });
  33. }
  34. private static void persist(final SeniorTracking device, final IResultCallback callback) {
  35. // Asynchronous - persist lost request into remote Crowd GPS Service
  36. Backendless.Persistence.save(device, new AsyncCallback<SeniorTracking>() {
  37. @Override
  38. public void handleResponse(SeniorTracking response) {
  39. // new LostDevice instance has been saved
  40. logger.debug("Device " + response.getImei() + " has been saved to Backendless. Remote object id=" + response.getObjectId());
  41. if (callback != null) {
  42. callback.response(response);
  43. }
  44. }
  45. @Override
  46. public void handleFault(BackendlessFault fault) {
  47. // an error has occurred
  48. logger.error("Could not persist data for IMEI=" + device.getImei() + "! Backendless Server reported an error code=" + fault.getCode() + ", " + fault.getMessage());
  49. if (callback != null) {
  50. callback.fault(fault.getCode(), fault.getMessage());
  51. }
  52. }
  53. });
  54. }

photo
1

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?

photo
1

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

photo
photo
1

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

photo
1

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.

photo
1

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)

  1. public class DataObject {
  2. ...
  3. private GeoPoint location;
  4. ...
  5. }

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

  1. public class DataObject {
  2. ...
  3. private List<GeoPoint> location;
  4. ...
  5. }

photo
1

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.

photo
1

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

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

photo
photo
1

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.

  1. 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> )

photo
1

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

photo
1

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

photo
1

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

photo
1

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 :-)

photo
1

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.

photo
1

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.

photo
1

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.

photo
photo
1

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

photo
1

Thank you guys for your effort.

I will let you know if I find any strange behaviour.

photo