question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor to use System.Text.Json

See original GitHub issue

Is 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:closed
  • Created 10 months ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
gfscommented, Feb 8, 2023

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.

1reaction
dbalikhincommented, Feb 7, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found