Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the JavaScriptSerializer class deprecated?

The MSDN documentation of the JavaScriptSerializer-class states:

Json.NET should be used serialization and deserialization. Provides serialization and deserialization functionality for AJAX-enabled applications.

Should this be some sort of deprecation hint or should this class not be used in general at all (for the purpose of JSON serialization)?

like image 917
0xDECAFBAD Avatar asked Oct 28 '16 09:10

0xDECAFBAD


People also ask

Is Newtonsoft JSON obsolete?

Newtonsoft. Json package is not provided by RestSharp, is marked as obsolete on NuGet, and no longer supported by its creator.

Why do we use JavaScriptSerializer?

NET Framework, use Newtonsoft. Json. The JavaScriptSerializer class is used internally by the asynchronous communication layer to serialize and deserialize the data that is passed between the browser and the Web server. You cannot access that instance of the serializer.

Is JSON net deprecated?

Json was basically scrapped by Microsoft with the coming of . NET Core 3.0 in favor of its newer offering designed for better performance, System. Text.

What is JavaScriptSerializer?

JavaScriptSerializer is a class that helps to serialize and deserialize JSON. It is present in the namespace System. Web. Script. Serialization is available in assembly System.


1 Answers

2021

In 2021 the JavaScriptSerializer is not only deprecated it has been removed in .Net Core and .Net 5.x. So you can't use this anymore unless your targeting the .Net Framework 4.8 or below.

The replacement is the System.Text.Json suite of classes.


Is it deprecated

No. Otherwise, they would have marked it obsolete.

should this class not be used in general

Providing your targetting .Net Framework 4.8 or below then sure you can use it, if you want to taregt .Net core or .Net 5 then you can't as it's not available anymore.


This is here as a comparision between the available .Net Framework classes. I actually go into more detail on System.Text.Json vs Json.Net in another answer.

Now is it the best serialiser to use? Basically no and even Microsoft know this and use Json.Net internally for things such as the Web.API. Hence the recommendation. It has several advantages over the JavaScriptSerializer. It seems the new Microsoft is attempting to embrace the open source community (hopefully not to extinguish it...) and utilise the wealth of tools out there.

It seems Microsoft can't make up their minds about making it actually obsolete. My guess is they still maintain it because it's used internally and re-writing stuff to use Json.Net is just more work than it's worth.

Tl;Dr

Use Json.Net if your targetting .Net Framework 4.8 or below, for .Net core or .Net 5 then you can choose between Json.Net or System.Text.Json.

like image 53
Liam Avatar answered Sep 28 '22 17:09

Liam