AGSCoding in Quartz

997
2
Jump to solution
11-22-2016 05:13 PM
JamesRichards1
Occasional Contributor

It looks like all of the initWithJSON and encodeToJSON methods have been removed in Quartz. Also, it seems like none of the objects conform to NSCoding. How can we serialize / deserialize objects in the Quartz SDK?

0 Kudos
1 Solution

Accepted Solutions
MaryHarvey
Esri Contributor

At version 100.0.0 Objects can be serialised if they conform to the AGSJSONSerializable Protocol. The methods to work with the JSON are toJSON and fromJSON.

do {jsonDict = try self.map.toJSON() as! NSDictionary
 } catch {
 print("Failed to obtain map json")
}‍‍‍‍

View solution in original post

0 Kudos
2 Replies
MaryHarvey
Esri Contributor

At version 100.0.0 Objects can be serialised if they conform to the AGSJSONSerializable Protocol. The methods to work with the JSON are toJSON and fromJSON.

do {jsonDict = try self.map.toJSON() as! NSDictionary
 } catch {
 print("Failed to obtain map json")
}‍‍‍‍
0 Kudos
JamesRichards1
Occasional Contributor

Mary, 

Thanks for letting me know about AGSJSONSerializable. 

A couple of points:

1. I think the documentation could be improved. For example, if you look at AGSEnvelope you can see in the class diagram that it conforms to AGSJSONSerializable by way of inheriting from AGSGeometry. But neither AGSEnvelope nor AGSGeometry lists the toJSON and fromJSON methods. If you look at AGSPortalItem, on the other hand, the documentation does list those methods. So it's a bit inconsistent and confusing.

2. Some classes that previously supported JSON serialization, such as AGSGraphic and AGSFeatureLayer, are no longer supported.

Thanks again!

James

0 Kudos