Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support for System.Text.Json #402

Open
qpooqp opened this issue Jan 31, 2025 · 1 comment
Open

Full support for System.Text.Json #402

qpooqp opened this issue Jan 31, 2025 · 1 comment
Assignees

Comments

@qpooqp
Copy link

qpooqp commented Jan 31, 2025

Motivation

In our solution we have need for serialization and deserialization of the models received from delivery client.
The models are generated by model generator.
The models have properties with interface types and the implementation of the interfaces are hidden from us because they are internal to the delivery client library. This causes problem when we want to deserialize them because System.Text.Json can't deserialize to interface without any concrete implementation.

An example can be interface Kontent.Ai.Delivery.Abstractions.IDateTimeContent.

Proposed solution

Expose implementations for the interfaces used in models generated by model generator.

Additional context

I hope that it is understandable what is going on here, but if not, then let me know and i will provide you with some example project.

@pokornyd pokornyd self-assigned this Feb 5, 2025
@pokornyd
Copy link
Member

pokornyd commented Feb 5, 2025

Hello and thank you for the submission.

Internally, the SDK uses ModelProvider class for mapping purposes, built around Newtonsoft.Json, which supports interface-to-type mapping. The generated models reflect that.

Assuming you're deserializing content from API, the item retrieval methods provide generic overloads (e.g. GetItemAsync<T>), where you can either provide the model directly, or pass in object and implement runtime type resolution.

That being said, you mentioned the need for both deserializing and serializing, which leads me to believe you might have a more specific scenario in mind. If that is the case, could you share some more details on the matter? In particular, is there a requirement on your end to use System.Text.Json rather than newtonsoft or the built-in SDK methods?

Also, while this doesn't necessarily relate to your issue, it should be pointed out the generator is outdated and currently doesn't align with some of the recent updates to delivery API, such as the addition of display_timezone property (datetime elements are still typed as DateTime? rather than IDateTimeContent). An update to the generator should be coming in the near future.

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

No branches or pull requests

2 participants