Skip to content

fix: add EmbeddedObject and EmbeddedObjectConverter to resolve IEmbeddedObject deserialization failure#69

Draft
OMpawar-21 wants to merge 2 commits into
developmentfrom
fix/DX-9288
Draft

fix: add EmbeddedObject and EmbeddedObjectConverter to resolve IEmbeddedObject deserialization failure#69
OMpawar-21 wants to merge 2 commits into
developmentfrom
fix/DX-9288

Conversation

@OMpawar-21

Copy link
Copy Markdown
Contributor

Problem

Calling .includeEmbeddedItems().Fetch<T>() on a model that implements
IEntryEmbedable throws a JsonSerializationException at runtime:

Could not create an instance of type Contentstack.Utils.Interfaces.IEmbeddedObject.
Type is an interface or abstract class and cannot be instantiated.
Path 'entry._embedded_items.rte_json[0]._content_type_uid'

IEntryEmbedable declares embeddedItems as
Dictionary<string, List<IEmbeddedObject>>. When the Delivery API returns
_embedded_items in the response, Newtonsoft.Json tries to instantiate
IEmbeddedObject directly. Because it is an interface, instantiation fails.

Changes

Contentstack.Utils/Models/EmbeddedObject.cs (new)

Concrete class implementing both IEmbeddedEntry and IEmbeddedAsset.
Newtonsoft.Json can instantiate this in place of IEmbeddedObject.
[JsonExtensionData] on the Fields property preserves any custom fields
on the embedded entry or asset (e.g. bio, email, avatar_url) that are
not explicitly declared.

Contentstack.Utils/Converters/EmbeddedObjectConverter.cs (new)

JsonConverter that intercepts IEmbeddedObject at deserialization time
and redirects to EmbeddedObject. CanConvert uses exact type equality
(==) rather than IsAssignableFrom so consumer-defined subclasses of
IEmbeddedObject are not intercepted.

Consumer Impact

No changes required in consumer code. Models implementing IEntryEmbedable
continue to work as-is after the delivery SDK registers EmbeddedObjectConverter
in ContentstackClient.

Testing

Verified with a .includeEmbeddedItems().Fetch<T>() call against a JSON RTE
field containing embedded entries and embedded assets:

  • BEFORE: throws JsonSerializationException
  • AFTER: deserializes successfully; uid, title, _content_type_uid and
    all custom fields are populated

Changelog

See CHANGELOG.md → Version 1.3.1

…ct deserialization

IEmbeddedObject is an interface and cannot be instantiated directly by
Newtonsoft.Json. Add EmbeddedObject as a concrete implementation covering
both IEmbeddedEntry and IEmbeddedAsset, and EmbeddedObjectConverter to
redirect deserialization from the interface to the concrete class.

EmbeddedObject uses [JsonExtensionData] so custom fields on embedded
entries and assets are preserved rather than silently dropped.
@OMpawar-21 OMpawar-21 requested review from cs-raj and reeshika-h June 23, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant