You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-28Lines changed: 33 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,44 +25,49 @@ From the terminal,in the name space where your class exists :
25
25
26
26
```javascript
27
27
Set obj = ##class(SampleApps.Serialize.MapTesting).%OpenId(1)
28
-
SetJSON=obj.Export()
29
-
Do JSON.%ToJSON()
28
+
SetobjJSON=obj.Export()
29
+
Do objJSON.%ToJSON()
30
30
31
31
Set newObj = ##class(SampleApps.Serialize.MapTesting).%New()
32
-
Do newObj.Import(,,JSON)
32
+
Do newObj.Import(,,objJSON)
33
+
set tSC = newObj.%Save()
34
+
write newOBJ.%Id()
33
35
```
34
36
We will have a new instance of _`SampleApps.Serialize.MapTesting`_ object, a clone of the one with ID=1. This was the example, we can modify it before saving or just discarding.
35
37
```
36
38
```
37
39
38
40
### What _`OPNLib.Serialize.Adaptor`_ provides?
39
41
40
-
Basically when we compile a class that inherits from our Adaptor, the class will have 4 new generic instance methods: `Export` and `Import` (that will act as dispatchers), and `exportStd` and `importStd` (that implements the logic to serialize/deserialize in/from JSON format). Also, and very important, it will be created a generic mapping between each of the properties in the Caché object and its equivalent serialized. That class mapping will be stored in 2 internal globals: `^MAPS` and `^MAPSREV` (**).
41
-
(**) Globals structure explained later on
42
+
Basically when we compile a class that inherits from our Adaptor, the class will have 4 new generic instance methods: `Export` and `Import` (that will act as dispatchers), and `exportStd` and `importStd` (that implements the logic to serialize/deserialize in/from JSON format). Also, and very important, it will be created a generic mapping between each of the properties in the Caché object and its equivalent serialized. That class mapping will be stored in 2 internal globals: `^MAPS` and `^MAPSREV` (Globals structure is explained in more detail in class documentation).
42
43
43
-
How is the mapping built at first place?
44
-
45
-
We can have several maps for a particular class (for example to exchange data from an object with different systems or organizations, we might need to export some properties but not others, or apply different conversions to some values, or name the properties differently , etc…).
46
-
47
-
By default, Adaptor will generate MAP0, and will make a direct mapping regarding property names (same name for target an source property).
48
-
49
-
Each property will be categorized in group types. Currently these are the group types supported :
50
-
1) Basic type
51
-
○ It'll include %String, %Integer, %Date, %Datetime,%Timestamp,%Decimal,%Float,… and most of the basic types defined in the %Library package
52
-
2) List collection
53
-
○ It'll include collections of datatypes of type %Collection.ListOfDT
54
-
3) Array collection
55
-
○ It'll include collections of datatypes of type %Collection.ArrayOfDT
56
-
4) Object Reference
57
-
○ A property that reference a custom object not in %* libraries
58
-
5) Array of objects and Relationship objects
59
-
○ A property of type %Collection.ArrayOfObject or a property of type %RelationshipObject with cardinality many or children
60
-
6) List of Objects
61
-
○ A property of type %Collection.ListOfObject
62
-
7) Stream
63
-
○ Properties of type %Stream.*, %CSP.*stream*,…
64
-
65
-
How could we configure our mapping for serialization?
44
+
### How is the mapping built at first place?
45
+
46
+
We can have several maps for a particular class (for example to exchange data from an object with different systems or organizations, we might need to export or import some properties but not others, or apply different conversions to some values, or name the properties differently , etc…).
47
+
48
+
By default, all classes that inherit from `OPNLib.Serialize.Adaptor` will have an associated default map: MAP0, that will make a direct mapping regarding property names (same name for target an source property).
49
+
50
+
Each property will be categorized in group types, numbered from 1 to 6. Currently these are the group types supported :
51
+
52
+
1. Basic type
53
+
* It'll include %String, %Integer, %Date, %Datetime,%Timestamp,%Decimal,%Float,… and most of the basic types defined in the %Library package
54
+
2. List collection
55
+
* It'll include collections of datatypes of type %Collection.ListOfDT
56
+
3. Array collection
57
+
* It'll include collections of datatypes of type %Collection.ArrayOfDT
58
+
4. Object Reference
59
+
* A property that reference a custom object not in %* libraries
60
+
5. Array of objects and Relationship objects
61
+
* A property of type %Collection.ArrayOfObject or a property of type %RelationshipObject with cardinality many or children
62
+
6. List of Objects
63
+
* A property of type %Collection.ListOfObject
64
+
7. Stream
65
+
* Properties of type %Stream.*, %CSP.*stream*,…
66
+
67
+
During map generation, by default, the Adaptor sets export and Import conversion methods for dates and streams (which are exported as base64 text)
68
+
69
+
70
+
### How could we configure our mapping for serialization?
66
71
67
72
We can have as much mapping definitions for a class as we need. An easy way to start to define our customized maps is exporting the default MAP0 and importing it again with a different name, then we can make changes in the map regarding the properties that should be exported /imported, names, conversor methods to apply (***)
68
73
(***) See OPNLIB.SERIALIZE.ADAPTOR.Serialize.Util library for tools to export/import maps, get / set property mappings,etc…)
0 commit comments