Skip to content

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

Merged
OMpawar-21 merged 4 commits into
developmentfrom
fix/DX-9288
Jun 24, 2026
Merged

fix: add EmbeddedObject and EmbeddedObjectConverter to resolve IEmbeddedObject deserialization failure#69
OMpawar-21 merged 4 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
reeshika-h
reeshika-h previously approved these changes Jun 24, 2026

@reeshika-h reeshika-h left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…ect deserialization

Add EmbeddedObject as a concrete implementation of IEmbeddedObject covering
both IEmbeddedEntry and IEmbeddedAsset. Add EmbeddedObjectConverter to redirect
deserialization from the interface to the concrete class. Custom fields on
embedded entries and assets are preserved via [JsonExtensionData].

Add unit tests covering CanConvert isolation, known field mapping, nested
object and array fields in [JsonExtensionData], full Delivery API response
shape, and regression guard for the interface instantiation crash.

@reeshika-h reeshika-h left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@OMpawar-21 OMpawar-21 marked this pull request as ready for review June 24, 2026 11:18
@OMpawar-21 OMpawar-21 requested a review from a team as a code owner June 24, 2026 11:18
@OMpawar-21 OMpawar-21 merged commit bb16f03 into development Jun 24, 2026
11 checks passed
@OMpawar-21 OMpawar-21 deleted the fix/DX-9288 branch June 24, 2026 11:19
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.

2 participants