Customize the serialization of a Sitecore field

Current version: 19.x

Customizing the serialization of a Sitecore field is one of the methods you can use to customize the data returned by the Layout Service.

To customize the serialization of a Sitecore field:

  1. Create an implementation of Sitecore.LayoutService.Serialization.FieldSerializers.BaseFieldSerializer.

  2. Override the WriteValue method and use the JsonTextWriter to create your custom JSON structure for the Field.

  3. Create an implementation of Sitecore.LayoutService.Serialization.Pipelines.GetFieldSerializer.BaseGetFieldSerializer.

  4. Override SetResult and set args.Result to an instance of your BaseFieldSerializer implementation.

  5. Patch the getFieldSerializer pipeline within the layoutService pipeline group with your BaseFieldSerializer implementation. You must patch before the GetDefaultFieldSerializer processor, and populate the FieldTypes list with the Sitecore field type(s) that you want.

Do you have some feedback for us?

If you have suggestions for improving this article,