Contentful .NET Sample Entry Model

What follows is my attempt to define an Entry Model class as described in the blog post https://deliverystack.wordpress.com/2020/07/20/net-core-headless-cms-entry-models-and-entry-model-classes/ to support the Content Type that I described in the blog post at https://deliverystack.wordpress.com/2020/07/21/entry-data-formats-in-headless-cms/ for the Contentful SaaS headless CMS.

https://pastebin.com/qKsX4DMW

I receive NullReferenceException when I try to access the Assets. This could make sense, because the JSON representation of the Entry does not include Asset metadata, so modeling Assets requires additional RESTful API calls that I do not want to investigate at this point. Here is the output.

https://pastebin.com/eRZ68cpJ

In addition to the problem with Assets, I object to using the Document class to model Rich Text Fields. I can write my own POCO to replace the Asset class provided by the vendors, but then I would have to copy the code for this Contentful Document class to a class that I can use in my Entry Models or introduce some other complexity, and I really don’t want to do that.

Maybe there are alternatives. Maybe I can implement a JsonConverter for populating the Entry Model, but I don’t want to convert the JSON representation of the markup to…markup unless something needs to use that markup, and I don’t want use or especially expose CMS vendor dependencies in my Entry Model classes, not even with dependency injection (there is no standard set of interfaces for headless CMS vendors to implement).

Maybe I can use something with a closure to defer the rendering or find some way to abstract the Contentful specifics. Unfortunately, no matter how much you try to avoid it, retrieving the raw HTML value of a Rich Text Field is often the primary use case in a (web) CMS implementation. Since this proprietary JSON format provides no value, I’m already frustrated by this system.

In any case, I get the impression that I would have to rewrite Contentful Entry Model classes or other significant logic to work with other headless CMS products. This may seem normal to developers working with other CMS products but feels like a violation of basic principles for .NET Core with headless CMS.

Published by John West

I like Twizzlers and um

One thought on “Contentful .NET Sample Entry Model

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: