Serialize xConnect entities using JSON.NET
This topic demonstrates how to serialize xConnect entities using JSON.NET. You may want to serialize xConnect objects if:
-
You want to cache facets in an external database.
-
You have a custom Web API endpoint that reads data using the xConnect client, acts on the data that is returned, and passes the modified data on to another service.
Keep international data privacy regulations in mind when writing contact and interaction data to a cache or database - for example, you may wish to avoid serializing contact facets marked [PIISensitive].
To serialize xConnect entities using JSON.NET, define a JsonSerializerSettings object as shown and pass this object into the SerializeObject method:
Asynchronous and synchronous extension methods
Asynchronous and synchronous extension methods
In a unit testing context, you can use the Sitecore.XConnect.Serialization.DeserializationHelpers class to set read-only properties on the Contact and Interaction classes. The following example demonstrates how to use the SetFacet() method: