Refactor to use System.Text.Json
See original GitHub issueIs your feature request related to a problem? Please describe.
App inspector deserializes using Newtonsoft.Json, accordingly it ignores System.Text.Json attributes. If you were to extend an AI rule with more attributes and then call AddString, even if you the T
is specified the deserialization may not be correct if your json properties dont match the attribute names or if they have special handling.
Any downstream users who implement extensions to AI (like DevSkim) are then required to include newtonsoft for the annotations to use the AddString
methods.
Describe the solution you’d like Ideally AppInspector could just use System.Text.Json for serialization in the rules path, using the standard attributes.
Issue Analytics
- State:
- Created 10 months ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Migrate from Newtonsoft.Json to System.Text.Json - .NET
The System.Text.Json namespace provides functionality for serializing to and deserializing from JavaScript Object Notation (JSON). The System.
Read more >How to serialize and deserialize JSON using C# - .NET
This article shows how to use the System.Text.Json namespace to serialize to and deserialize from JavaScript Object Notation (JSON).
Read more >Introduction to System.Text.Json Through Examples
System.Text.Json library helps us handle JSON in ASP.NET applications. It comes integrated with the framework and it's simple and easy to ...
Read more >System.Text.Json: Deserialize JSON with automatic casting
The new System.Text.Json api exposes a JsonConverter api which allows us to convert the type as we like. For example, we can create...
Read more >Should you use Newtonsoft.Json or System.Text. ...
Json uses Textwriters I think and strings which are represented as utf-16 internally. System.Text.Json works directly with buffers in UTF-8 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also, no concerns about using the string version in the HTML report, as mentioned earlier we are in planning to replace it with an improved implementation. That is a known limitation of the current HTML report that won’t be addressed until the rewrite.
I think I found alternative solution to simply use StreamWriter. It should save some memory and it copies logic from TextWriter in AI. Please take a look and probably do benchmarks (I pushed my changes). Please note that HTML Writer will still use the string in memory, because it was existing behaviour. But SARIF and JSON Writers are good to go. Now it will use this:
JsonSerializer.Serialize(StreamWriter.BaseStream, log);
StreamWriter plays nice with Console output and it inherits from TextWriter.