In April 2019, I wrote the article announcing the forthcoming Sitecore upgrade. And here it is — the version 9.2 of Sitecore Experience Platform has been officially released on July 22, 2019.
Today, I will not tell you about all the new features in Sitecore 9.2 but would like to draw your attention to the serialization mechanism.
The process of serialization helps transform data items to text files or memory buffers for their further storage, transfer and reconstruction. It is especially useful for a team of developers who work together on the same project and need to seamlessly synchronize changes between their individual development environments.
In Sitecore 9.2, a new serialization config file appeared in the CMS.Core folder: App_Config\Sitecore\CMS.Core\Sitecore.Serialization.config file.
![Sitecore-9.2-serialization-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/File_Config_Location_1.png)
This file contains different parameters. The most interesting of them are:
- Serialization type (currently, there are two possible variants — default and YAML; keep in mind that by default it is not YAML)
<setting name=”Serialization.SerializationType” value=”default” />
![Sitecore-Serialization-YAML-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Config_Serialization_Types_1.png)
- Serialization folder (the root of the serialized items)
<setting name=”SerializationFolder” value=”$(dataFolder)/serialization” />
![Config Data Folder](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Config_Data_Folder_1.png)
- Field formatters (only works with YAML and defines serialization rules for specific item field types; if you have your custom field type, you will need to develop your own formatter and put it into this section)
- Predicate (only works with YAML; defines which roots should be serialized; by default, two values are used – master and core, that means that the serialization process will serialize all items defined under /Sitecore content path for both core and master database)
- userPredicate (initially, it’s an empty section; only works with YAML)
<userPredicate></userPredicate> - rolePredicate (initially, it’s an empty section; only works with YAML)
<rolePredicate></rolePredicate>
How Can You Execute Serialization Functions in Sitecore?
There are three options:
![Sitecore-9.2-Manual-Serialization-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/ContentEditor_Manual_Serialization.png)
1. Do it manually in the Content Editor
2. Do it automatically by using Sitecore event handlers. For instance:
![Serialization-functions-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Way2_EventQueeSavedItem.png)
3. Use the Sitecore service page
[your Sitecore cm instance host name]/sitecore/admin/serialization.aspx
![Way3_Serialization](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Way3_Serialization.png)
I’d like to perform both default and YAML serialization manually. Well, I have Sitecore 9.2 installed. Let’s serialize one item using Sample Rendering item (it goes out of the box):
![Sample Render](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Sample_Render.png)
To serialize this item manually, I have to engage the Developer tab in the Content Editor (right click on any place at the top Content Editor Sitecore ribbon and select Developer).
![Developer_Panel](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Developer_Panel_1.png)
Then, select Sample Rendering item, and in the appeared panel click Serialize item.
![Serialization-in-Sitecore-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/CE_SerializeItem_1.png)
As I’ve mentioned before, we have a default serialization (by default). The serialized result is located in the data folder that was specified in the config file (by default App_Data/serialization).
![CE SerializeItem](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/CE_SerializeItem_2.png)
Let’s open this file. It looks like this:
![Default-Serialization-Sitecore-image](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/DefaultSerializedFile.png)
Now, let’s change the default serialization to YAML.
![Yaml-serialization-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Yaml1.png)
In the config file, change the parameter Serialization type to YAML. But be careful, for the YAML serialization we have a Predicate parameter which serializes all items. In our case, we want to serialize only one item that’s why we change the predicate as follows:
![Yaml2](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Yaml2.png)
Don’t forget to save changes and go back to the Content Editor. Repeat the serialization process once again. In the folder, the serialized item in the YAML format appears. Take a look at the result:
![Yaml-result](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Yaml-result.png)
Below you can see the comparison of the default and YAML files:
![Serialization-in-Sitecore-9.2-photo](https://www.sam-solutions.com/blog/wp-content/uploads/2019/07/Comparison.png)
To Sum Up
It’s great news that Sitecore has implemented YAML for serialization as this format is very convenient and widely used by developers.
Some benefits of YAML:
- YAML is a human-friendly format
- It is not comma separated
- It Supports different datatypes
- It is used by many technologies and is gaining popularity
Read more about Sitecore Serialization here.
Happy serialization, Sitecorian friends 🙂
I blog frequently and I really thank you for your information. The article has truly peaked my interest.