Hi,
This is the problem with Graphic object. The object can have a Map of data that can be retrieved when the user clicks on the drawn Graphic on the map. One of the constructor of the Graphic class has a parameter with type Map<String, Object> to store data, but somehow, when I retrieved it using Graphic.getAttributes() and access the value inside the Map, it returns a string (or ClassCastException when I try to cast it to an object of desired type, which of course, is derived from Object class)
It seems that the method cast all the Map values into string (maybe using toString() method). This is quite problematic, especially when the user wants to put a custom Object type to the Map as value.
The Graphic object should be able to store and return back the object without changing it to String
HashMap<String, Object> data = new HashMap<String, Object>()
MyObject obj = new MyObject();
data.put("data", obj);
Graphic g = new Graphic(point, image, data);
MyObject selected = (MyObject) g.getAttributes().get("data"); // Exception here
Hi Jason Christian,
Is this Runtime version 100 or is this version 10.2.8-1?
Additionally, what type of object are you trying to store?
Thanks,
Alexander
It's on version 10.2.8-1
The objects are just plain made Java object. (e.g. a custom data structure)
Hi ihazbackup
I have a sinking suspicion that custom data types are not supported. The feeling is that if ArcGIS Online supports the data type that it would be supported here as the data type is supposed to mirror that of field data that you would find in ArcGIS Online. A workaround might be to convert the POJO to a BLOB and then store it and when you go to retrieve it, convert the BLOB back to a POJO. This is just a guess and can vary from data type to data type. I will investigate some more on my end.
Thanks,
Alexander
Currently only String is supported on the android's arcgis SDK. Aside from POJO, you can also use GSON to store the data structure as JSON string. But, for a complex object, it might not suffice.
Based on that response, I take it that you are having trouble storing longs, doubles, and booleans in the map?
Thanks,
Alexander
Currently, I don't have a problem with storing data on a Graphic marker (because I just changed the algorithm to just search on the list of objects rather than type-casting the attributes from HashMap). I just want to address the problem of not being able to retrieve objects from attributes from Graphic marker
Earlier you mentioned that only strings are supported but are you able to store other primitive data types (longs, doubles, booleans, etc...) in the Graphics object and retrieve them? This will help us understand the exact behavior that you are experiencing and we will be better able to address it. Based upon the documentation, I would beleive that only field types that are supported by ArcGIS Online are supported in the graphics attributes property. These fields are Date, Double, Integer, and String. I will need to investigate more on my end to bring back more information.
Thanks,
Alexander
Hi Jason Christian,
From the documentation for Graphic,
A Graphic's attributes are stored in a Map. Supported value types are restricted to the following list:
- Short
- Integer
- Long
- Float
- Double
- Boolean
- String
- Date
- Calendar
- null
This means that if you want to store an Object inside the map, it needs to conform to one of the listed data types. You can find more information on Graphics at this link: