.NET Core Headless CMS Entry Models and Entry Model Classes

An object that represents an Entry is an Entry Model. A class used for Entry Models is an Entry Model class. You can implement an Entry Model class for each of your Content Types. You may choose to implement a class hierarchy for Entry Models based on any inheritance hierarchy apparent in your Content Types.

You can implement additional Entry models for other purposes. For example, you can implement Entry Models for Content Types that have Fields in common, allowing a single Entry Model class to model aspects common to multiple Content Types where those Content Types may not support an Entry Model class hierarchy, such as Content Types from multiple CMS repositories. You may use Entry Models as view models in ASP.NET MVC applications. You may use one or more Entry Models specifically for serialization to a simplified JSON format for indexing by a search engine or to embed in HTML transmitted to clients.

When you access a headless CMS, you retrieve JSON representations of Entries. You can process this JSON yourself, or you can deserialize that JSON to an object of the class that you choose. If you use an object to model an Entry, that object is an Entry Model. The class that defines an Entry Model is an Entry Model class.

An Entry Model is a Plain Old CLR Object (POCO, https://en.wikipedia.org/wiki/Plain_old_CLR_object) that does not need to inherit from any specific base class or implement any interface and should not depend on any SDK from a CMS vendor. If the identifier of a Field in the Entry (which appears in the JSON) does not match the name of the property in the Entry Model class, then decorate that property with JsonPropertyAttribute (https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonPropertyAttribute.htm) to specify the corresponding Field identifier. 

[JsonProperty(propertyName: "title")]
public string EntryTitle { get ; set ; }

You can use the .NET SDKs from the CMS vendors to manage deserialization from JSON when you retrieve Entries. Typically, you pass your class as a generic parameter to a method in the SDK along with Entry identifiers or a query that identifies one or more Entries. The SDK returns objects of the generic type that you specify with properties populated from the JSON representation of the entry.

Some SDKs provide explicit facilities to access the raw JSON retrieved from the CMS. For others, you may be able to pass JObject or string as the generic type to retrieve the JSON. If you cache the JSON representation of an Entry, then you can deserialize that data yourself to any number of objects using the types of your choice.

Published by John West

I like Twizzlers and um

12 thoughts on “.NET Core Headless CMS Entry Models and Entry Model Classes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: