Customize the serialization of a Sitecore field
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:
-
Create an implementation of
Sitecore.LayoutService.Serialization.FieldSerializers.BaseFieldSerializer
. -
Override the
WriteValue
method and use theJsonTextWriter
to create your custom JSON structure for theField
. -
Create an implementation of
Sitecore.LayoutService.Serialization.Pipelines.GetFieldSerializer.BaseGetFieldSerializer
. -
Override
SetResult
and setargs.Result
to an instance of yourBaseFieldSerializer
implementation. -
Patch the
getFieldSerializer
pipeline within thelayoutService
pipeline group with yourBaseFieldSerializer
implementation. You must patch before theGetDefaultFieldSerializer
processor, and populate theFieldTypes
list with the Sitecore field type(s) that you want.