Maptitude GISDK Help |
You can serialize a GISDK object into an options array so that it can be stored in a file and later on to be deserialized back into a GISDK object.
There are two GISDK functions for serialization:
GISDK Function |
Summary |
Serializes a GISDK object into an options array |
|
Deserializes an options array into a GISDK object |
The GISDK functions are called as follows:
array arr = Serialize(object obj)
Serializes an object. The input object must be of type "object" (an instance of a GISDK class). Returns an array representing the serialized object.
object obj = Deserialize(array arr)
Deserializes the input array. If it is valid, the returned object is an instance of a GISDK class.
The following object property types can be serialized:
INT
DOUBLE
STRING
NULL
ARRAY
COLOR
COORD
OBJECT
DATETIME
To serialize a GISDK class that contains properties with additional types, you must implement a macro named "Transient" in your GISDK class. The Transient macro must return an array of property names that should be ignored by the serialization process.
You can also implement your own custom serialization format by implementing two macros named "Serialize" and "Deserialize" in your GISDK class.
Here is an example:
Class "test"
init do
self.int = 2
self.double = 2.0
self.str = "this is a string"
self.nothing = null
self.array = {1,2,3,4}
self.color = ColorRGB(255, 255, 255)
self.coord = Coord(100, 100)
self.obj = CreateObject("nestedObject")
self.datetime = CreateDateTime(22, 3, 2011, 18, 30, 06)
//Transient variables wont be serialized!!
self.jclient = CreateManagedObject("System.Net.Http", "System.Net.Http.HttpClient",)
endItem
//Transient variables wont be serialized!! You have to implemented
Macro "Transient" do
return({"jclient"})
endItem
Macro "Serialize" do
self.dllName = "System.Net.Http"
self.dllClass = "System.Net.Http.HttpClient"
endItem
Macro "Deserialize" do
self.jclient = CreateManagedObject(self.dllName, self.dllClass,)
endItem
endClass
Class "nestedObject"
init do
self.id = "nested object"
endItem
endClass
Macro "unitTest"
test = CreateObject("test")
serialized = Serialize(test)
testDeserialized = Deserialize(serialized)
assert(test.int = testDeserialized.int, "integer test failed!")
assert(test.double = testDeserialized.double, "double test failed!")
assert(test.str = testDeserialized.str, "string test failed!")
assert(test.nothing = testDeserialized.nothing, "null test failed!")
//test array
assert(test.array.length = testDeserialized.array.length, "array test failed!")
for i = 1 to test.array.length do
assert(test.array[i] = testDeserialized.array[i], "array test failed!")
end
assert(test.color = testDeserialized.color, "color test failed!")
assert(test.coord = testDeserialized.coord, "coord test failed!")
assert(TypeOf(testDeserialized.obj) = "object", "obj test failed!")
assert(testDeserialized.obj.id = "nested object", "obj test failed!")
assert(test.datetime = testDeserialized.datetime, "datetime test failed!")
assert(TypeOf(testDeserialized.jclient) = "managedobject", "transient test failed!")
ShowMessage("unit test for serialization and deserialization Succeed!!!")
endMacro
©2025 Caliper Corporation | www.caliper.com |