-
Notifications
You must be signed in to change notification settings - Fork 0
Serialization
The list of all your serializations must be referenced in an XML or JSON file. The path to this file must be defined in the file config.json with the key serializationList (see Installation page for more informations).
You have to specify the manifest serialization list version to determine witch parser will be used to parse the document. There is currently only one version allowed 2.0.
If you decide to define your serialization list in XML format, your file must have "xml" extention and content must look like :
<serializations version="2.0">
<list>
<person>relative/path/to/person/serialization/manifest.xml</person>
<house>relative/path/to/house/serialization/manifest.xml</house>
<town>relative/path/to/town/serialization/manifest.xml</town>
</list>
</serializations>If you decide to define your serialization list in JSON format, your file must have "json" extention and content must look like :
{
"version" : "2.0",
"list" : {
"person" : "relative/path/to/person/serialization/manifest.json",
"house" : "relative/path/to/house/serialization/manifest.json",
"town" : "relative/path/to/town/serialization/manifest.json"
}
}As you can see the list permit to associate a name to a serialization path. Each name is unique and each manifest path must have "xml" or "json" extention. Finally the serialization path must be relative to the folder that contain serialization list file.
A Serialization is attached to a model and permit to serialize/deserialize (save/load) object in/from a specific input/output. For example I have defined a manifest Person and I want to serialize persons in sql database; I have to define table name and database connection.
Serialization settings are described by their own manifest (for example for sql database serialization, there is a manifest sqlDatabase and a manifest sqlTable). All allowed serializations are referenced in manifest list in Comhon/Manifest/Collection/Serialization/serializationList.json file.
You have to specify the manifest serialization version to determine witch parser will be used to parse the document. There is currently only one version allowed 2.0.
Serializations can be defined in XML or JSON format. For each example we will illustrate XML and JSON format.
<manifest version="2.0">
<serialization/>
<properties/>
</manifest>{
"version": "2.0",
"serialization" : {},
"properties" : []
}- serialization node describe your serialization settings
- properties node describe some needed properties informations for serialization
- table in sql database :
sqlTable(local or distant) - json file :
jsonFile(local) - xml file :
xmlFile(local)
There is two way to define your serialization settings :
1. describe directly your serialization settings (see corresponding manifest to know how to describe your serialization)
<manifest version="2.0">
<serialization type="jsonFile">
<value saticPath="/asolute/path/to/a/folder" staticName="a_file_name.json"/>
</serialization>
<properties/>
</manifest>{
"version": "2.0",
"serialization": {
"type": "jsonFile",
"value": {
"saticPath": "/asolute/path/to/a/folder",
"staticName": "a_file_name.json"
}
}
}2. reference an id of a serialization (obviously reference a serialization that has been serialized)
<manifest version="2.0">
<serialization type="sqlTable" id="a_table_id"/>
<properties/>
</manifest>{
"version": "2.0",
"serialization": {
"type": "sqlTable",
"id": "a_table_id"
}
}Properties node is a list of properties. Each property node refer to a property in corresponding Model.
For the following explanations we will build a serialization Person like example.
some serialization doesn't manage certain characters so you can replace a property name when you serialize your Object. For example pgsql doesn't manage columns names with uppercase, so if you have a property name APropertyName you can define a serialization name a_property_name that will match with your column name.
<manifest version="2.0">
<serialization type="sqlTable" id="person"/>
<properties/>
<firstName serializationName="first_name"/>
</properties>
</manifest>{
"version": "2.0",
"serialization": {
"type": "sqlTable",
"id": "person"
},
"properties": {
"firstName": {
"serializationName": "first_name"
}
}
}Aggregation is a way to associate a model to others models by matching properties. This information is used only for slqTable serialization. For example model Person has a foreign property homes (see Manifest page), model Home has it own serialization and would have a property owner (serialized in a column like owner_id or person_id), so aggregation would refer owner and look like :
<manifest version="2.0">
<serialization type="sqlTable" id="person"/>
<properties>
<homes>
<aggregations>
<aggregation>owner</aggregation>
</aggregations>
</homes>
</properties>
</manifest>{
"version": "2.0",
"serialization": {
"type": "sqlTable",
"id": "person"
},
"properties": {
"homes": {
"aggregations": [
"owner"
]
}
}
}A property can refer to several aggregations :
<manifest version="2.0">
<serialization type="sqlTable" id="person"/>
<properties>
<children>
<aggregations>
<aggregation>mother</aggregation>
<aggregation>father</aggregation>
</aggregations>
</children>
</properties>
</manifest>{
"version": "2.0",
"serialization": {
"type": "sqlTable",
"id": "person"
},
"properties": {
"children": {
"aggregations": [
"mother",
"father"
]
}
}
}<manifest version="2.0">
<serialization type="sqlTable" id="person"/>
<properties>
<firstName serializationName="first_name"/>
<birthPlace serializationName="birth_place"/>
<father serializationName="father_id"/>
<mother serializationName="mother_id"/>
<children>
<aggregations>
<aggregation>mother</aggregation>
<aggregation>father</aggregation>
</aggregations>
</children>
<homes>
<aggregations>
<aggregation>owner</aggregation>
</aggregations>
</homes>
</properties>
</manifest>{
"version": "2.0",
"serialization": {
"type": "sqlTable",
"id": "person"
},
"properties": {
"firstName": {
"serializationName": "first_name"
},
"birthPlace": {
"serializationName": "birth_place"
},
"father": {
"serializationName": "father_id"
},
"mother": {
"serializationName": "mother_id"
},
"children": {
"aggregations": [
"mother",
"father"
]
},
"homes": {
"aggregations": [
"person"
]
}
}
}