Unplanned
Last Updated: 27 Nov 2024 11:32 by ADMIN
Azhar
Created on: 11 Feb 2021 11:03
Type: Feature Request
61
Migrate to System.Text.Json for serialization, instead of using Newtonsoft.Json

I have projects on .NET Core and I want to use the System.Text.Json serializer that is the new default, but reporting relies on Newtonsoft.Json.

---

ADMIN EDIT

There are two approaches that can be taken right now to solve this:

OPTION 1: define separate endpoints (services, projects) for the different tasks - they can still use the same database layer through a shared project, depending on the architecture you have. This would let you have separated services with the appropriate serializers without custom attributes and code (see below). For example, create a separate project for the reporting REST services.

OPTION 2: add some custom decoration on the endpoints so you can choose which serializer is used on each, you can find some examples here: https://stackoverflow.com/questions/59650907/how-to-configure-two-json-serializers-and-select-the-correct-one-based-on-the-ro - the point being to register a serializer depending on the endpoint based on your own code rather than let the framework put one in for all endpoints.

NOTE: This would be a breaking change.

---

13 comments
ADMIN
Dimitar
Posted on: 27 Nov 2024 11:32

Hello Diego,

Yes, the feature wasn't completed for the 2024 Q4 release, unfortunately.

We will try to complete the process of replacing Newtonsoft.Json with System.Text.Json in our code during the next year.

This item's status will be updated as soon as the feature is planned for an official release, please stay tuned.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Diego
Posted on: 20 Nov 2024 15:55
No change of serialization on 2024 R4 release. Right?
ADMIN
Dimitar
Posted on: 27 Aug 2024 13:20

Hello Thomas,

The feature was in development for the Q3 2024 release but unfortunately, we were unable to complete it back then and it was thus not included.

We hope to be able to complete it by the end of the year or by the middle of next year but I cannot yet confirm in which release it will be included.

Please stay tuned to this item as we will update it as soon as we have news on the matter.

Thank you for your understanding!

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Thomas
Posted on: 26 Aug 2024 11:10
I was just checking in, it seems like the serialization changes missed the 2024 R3 release.  Can you confirm that, and if it did miss this release is it on track for the Q4 release or are we looking at 2025 R1?
ADMIN
Dimitar
Posted on: 01 Jul 2024 09:06

Hello Diego,

The feature is currently in development and the release date is indeed planned for 2024 Q3

Regarding the second question, so far, we have not planned to release an internal build with the feature as it is still under active development.

Please stay tuned to this thread for future updates on the matter.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Diego
Posted on: 24 Jun 2024 13:08

Hi to all,

I have to organize my tasks for Q3-Q4 2024 and I would like to introduce a few simple reports to one of my customer products. I would like to know if migration to System.Text.Json library is confirmed for Q3.

Second, is there any way to get "alpha" packages of Q3 version?

Thanks.

ADMIN
Todor
Posted on: 24 Nov 2023 11:31

Hi Thomas,

The code shared by Dominik works as expected. I think it is fine to apply the approach in your Reporting projects.

We need to discuss the implementation within the team and decide whether we may recommend it to our users. We will follow up in the thread when we have something to share.

Regards,
Todor
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Thomas
Posted on: 17 Nov 2023 21:56

Domink:
Thanks for the solution, it works like a charm.  

 

@Momchil can you guys take a look at Dominics solution and see if its feasible to integrate into the solution.  I completely agree that adding the two serialization engines to the service container is a bad idea.  No matter the order, .Net 8 seems to want to use Newtonsoft instead of System.Text.Json which is the opposite of what we want.

ADMIN
Momchil
Posted on: 18 Oct 2023 14:43

Hello Dominik,

Thank you for pointing out the issue with our demos.

I looked into it and found that after the R3 2023 release, all HTML5 integration demos now target .NET 6 so keep in mind that the .NET 7 demo is affected as well.

This is why I have logged a bug item on your behalf and added your vote to it. I am also updating your account's Telerik Points as a token of gratitude.

Best Regards,
Momchil
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Dominik
Posted on: 17 Oct 2023 20:38

I have attached a working sample based on "Progress\Telerik Reporting R3 2023\Examples\CSharp\.NET 8\Html5IntegrationDemo"

What I changed:
- Added 
--ToNewtonSoftActionFilter, NewtonSoftJsonModelBinder, ValidateModelStateAttribute
--ReportDesignerControllerSTJBase, ReportsControllerSTJBase
- Program.cs
-- Removed AddNewtonsoftJson
-- Added "builder.Services.AddSingleton<ToNewtonSoftActionFilter>();"
- ReportDesignerController and ReportsController use the new base classes

@Telerik You might want to update your NET8 sample. It still points to NET6.

Gabriel
Posted on: 17 Oct 2023 11:59

I'd be very interested in your solution. Could you post a complete example?

 

Thank you.

Dominik
Posted on: 14 Oct 2023 19:55

I didn't like either option. So I've made a modification to the second one.

I didn't like the first because that would mean too much overhead and I really wanted to avoid adding NewtonsoftJson to the service container. The two aren't really mean to coexist and the hack may break on any change on either package.

So instead of using a "MySuperJsonInputFormatter" which I also dislike because of its global nature, I did the following:
I created a wrapper Controller for 
ReportDesignerControllerBase and ReportsControllerBase which has a ServiceFilterAttribute attached to it which will take the result object of any endpoint, use the newtonsoft serializer to produce a json string and replace the endpoint result with that. The request parameters which are classes have a ModelBinderAttribute attached which will cause the objects to be deserialized by newtonsoft.

Example:

[ServiceFilter(typeof(ToNewtonSoftActionFilter))]
public class ReportsControllerSTJBase : ReportsControllerBase {

...

[HttpPost("clients/{clientID}/instances/{instanceID}/documents", Order = -1)]
public virtual new IActionResult CreateDocument(string? clientID, string? instanceID, [FromBody][ModelBinder(typeof(NewtonSoftJsonModelBinder))] CreateDocumentArgs args) => base.CreateDocument(clientID, instanceID, args);

...

}

With this I only need to add the NewtonSoft package but the usage is completely confined to the two controllers. No ".AddNewtonsoftJson" or any global Formatters. And I haven't had any problems since I started using it many month ago.

To make this work less tedious, I've automated the creation (by using reflection) to create those wrapper classes.

 

Now here is my question:
I'd much rather not have to create those wrapper classes myself, instead it would be awesome if this or something like it was already contained in the package, for various reasons. So would it be possible to include something like that?

If interested I could clean up the code a bit more and post it here.

kdubious
Posted on: 08 Dec 2022 14:13

>> NOTE: This would be a breaking change.

Understood. But without this fix, one cannot use Kendo and Telerik Reporting in the same .NET6 app.