JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.76k stars 3.25k forks source link

Support for JsonSerializer.Context when StreamingContext is removed #2953

Open jdom opened 4 months ago

jdom commented 4 months ago

Since the StreamingContext type is Obsolete in .NET 8, is there a future plan for supporting a serialization context in the future? StreamingContext was used in the BinaryFormatter infrastructure, which is going away, although Newtonsoft.Json uses this type for non-BinaryFormatter purposes. The current workaround is to suppress the warning when using the JsonSerializer.Context property (when newing up StreamingContext actually), but it's not ideal.

If I read the BinaryFormatter obsoletion roadmap correctly, the type will not be removed in future versions (hopefully), so it might not be completely blocking given the workaround, but it's still worth some consideration.

elgonzo commented 4 months ago

EDIT: Oh, never mind, my apologies. Ignore my comment please, i didn't notice you're a Microsoft guy...

is there a future plan for supporting a serialization context in the future?

In my opinion, since quite a while already Newtonsoft.Json is basically a legacy library in maintenance mode, with System.Text.Json being the modern .NET json serializer that is in active development and part of the .NET BCL. Don't get you hopes up for Newtonsoft.Json receiving any noteworthy new features. If you need to maintain Newtonsoft.Json in an existing project, the workaround is (and quite likely will remain in the future) suppression of the SYSLIB0050 obsoletion warning for the StreamingContext ctor's.

jdom commented 4 months ago

Thanks @elgonzo , I think your opinion is valid, as I expected this too as a way to mark this issue as by design, if we believe we won't be blocked by it in the future. I do work at Microsoft, but I'm not in the .NET team, so for this issue I'm just a random consumer of the library.

markm77 commented 1 month ago

I also get warnings in .NET 8 for code like:

jsonSerializerSettings.Context =
    new StreamingContext(
        StreamingContextStates.All,
        optionsDict);

Warnings are:

Warning SYSLIB0050 : 'StreamingContextStates' is obsolete: 'Formatter-based serialization is obsolete and should not be used.' (https://aka.ms/dotnet-warnings/SYSLIB0050)
Warning SYSLIB0050 : 'StreamingContext.StreamingContext(StreamingContextStates, object?)' is obsolete: 'Formatter-based serialization is obsolete and should not be used.' (https://aka.ms/dotnet-warnings/SYSLIB0050)

Will this code break in .NET 9?