Android SDK 100.6 - How to convert Feature into JSON?

505
0
11-25-2019 07:46 AM
OscarDiago_Alonso
New Contributor III

I'm  migrating an Android application that used the ESRI SDK 10.2.8 into SDK 100.6.

In order to add new features, the application needs to use a custom service whose main parameter is the Feature in JSON format.

In the old version, the new element to insert was a Graphic and that object had the .toJson() method. In the new SDK the Grpahic object still exists, but it is not used for the same and the method to transform it into a JSON is gone. I have built an object Feature with the new element I want to add, but I have no idea how to convert that to JSON.

What I have tried so far:

ArcGISFeature f = objectToFeature(myObject);

try {
	FeatureCollection fc = new FeatureCollection();

	FeatureCollectionTable testTable = new FeatureCollectionTable(f.getFeatureTable().getFields(), GeometryType.UNKNOWN, SpatialReferences.getWgs84());
        ListenableFuture future = testTable.addFeatureAsync(f);
	future.get();
	fc.getTables().add(testTable);

	fc.loadAsync();

	fc.toJson();

		} catch (Exception ex) {
			String c = "";
		}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I thought this was the way to go, but the "addFeatureAsync" is not working and throwing the error:

com.esri.arcgisruntime.ArcGISRuntimeException: Abort due to constraint violation

No idea which constraint it is talking about. 

Is there an easier way (or another way) to obtain the JSON of the new Feature I have created?

Thanks for any help!!

0 Kudos
0 Replies