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.
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” />
- Serialization folder (the root of the serialized items)
<setting name=”SerializationFolder” value=”$(dataFolder)/serialization” />
- 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)
- rolePredicate (initially, it’s an empty section; only works with YAML)
How Can You Execute Serialization Functions in Sitecore?
There are three options:
1. Do it manually in the Content Editor
2. Do it automatically by using Sitecore event handlers. For instance:
3. Use the Sitecore service page
[your Sitecore cm instance host name]/sitecore/admin/serialization.aspx
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):
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).
Then, select Sample Rendering item, and in the appeared panel click Serialize item.
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).
Let’s open this file. It looks like this:
Now, let’s change the default serialization to YAML.
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:
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:
Below you can see the comparison of the default and YAML files:
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 🙂