dotnet / dotnet/aspnetcore

Questions about using AddNewtonsoftKinson during custom converter usage in .net6

Open
#51,643 0 comments 0 reactions 0 assignees View on GitHub
area-mvc Author: Migration Bot :robot:
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/Questions-about-using-AddNewtonsoftKinso/10488437)._

---
[severity:Other]
Version: .net6
Issue: Added an issue in the program where the custom converter for System.Text.Json.Serialization that registered AddNewtonsoftJson and then wrote in the code did not take effect.
Looking for the official instructions, I saw the following:
1. AddNewtonsoftJson replaces the default input and output formatter based on System.Text.Json, which is used to format all JSON content.
![image.png](https://aka.ms/dc/image?name=B41dc4a988fb941a6adc6cffe8a46f9da638325926560434070_20231011-114413-image.png&tid=41dc4a988fb941a6adc6cffe8a46f9da638325926560434070)
2. Based on the first point, NewtonsoftJson is equivalent to replacing System.Text.JSON as a built-in converter, so I should observe the following when using it: only if the applicable custom converter is not registered, the built-in converter will be selected.
![image.png](https://aka.ms/dc/image?name=B1789bdb44b274e36a7994f855b0d9247638325927662293584_20231011-114605-image.png&tid=1789bdb44b274e36a7994f855b0d9247638325927662293584)
3. Based on the second point, I used a custom converter that inherits System.Text.JSON in my code, and registered with the property with the highest priority, then the custom converter should have the highest priority and should take effect. But the truth is that it didn't work.
![image.png](https://aka.ms/dc/image?name=B85267569cc724a109d406ce413cbcc7d638325928595799038_20231011-114738-image.png&tid=85267569cc724a109d406ce413cbcc7d638325928595799038)
In summary: The current understanding is that when AddNewtonsoftJson is not used, the priority is according to the official given, the attribute registration is the highest, and it is effective. When using AddNewtonsoftJson, the official System.Text.JSON is set by NewtonsoftJson by default, System.Text.JSON is not effective. Doubt: According to the official priority and the instructions in the second point above, if I customize the converter and register it according to the highest priority attribute, whether or not I use AddNewtonsoftJson, it should actually take effect. We should follow the principle of priority, otherwise, once I use AddNewtonsoftJson, I can't use System.Text.Json's custom converter?

---
### Original Comments

#### Feedback Bot on 10/11/2023, 00:47 AM:

(private comment, text removed)
#### Feedback Bot on 10/11/2023, 02:46 AM:

(private comment, text removed)

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.