All Questions
Tagged with asp.net-core-3.0 system.text.json
16
questions
0
votes
1
answer
810
views
how to handle enums like strings and ints
I'm rewriting an api, switching from newtonsoft.json to system.text.json, and an issue i have is the fact that in some cases we send enums as ints and sometimes as strings.
Consider this example:
{
&...
5
votes
1
answer
3k
views
How to deserialize part of json using System.Text.Json in .net core 3.0?
I have a json from here https://api.nasa.gov/insight_weather/?api_key=DEMO_KEY&feedtype=json&ver=1.0 which looks like:
{
"782": {
"First_UTC": "2021-02-06T17:08:...
3
votes
0
answers
919
views
Is there an alternative to StringEnumConverter in .Net Core 3?
In .net core prior to version 3 there when Newtonsof.Json was used there was a possibility to inherit from StringEnumConverter to add additional validation or a custom error message for the process of ...
12
votes
7
answers
26k
views
.NET Core 3 [JsonIgnore] not working when requesting single resource
In my .net Core 3.0 API the [JsonIgnore] Attribute is not working as excepted. Im using System.Text.Json
Instead of the old Newtonsoft.Json
When I'm using my resource that returns a list of Objects, ...
3
votes
1
answer
2k
views
Read single record at a time with System.Text.Json
I am trying to read a single json record into memory at a time using .net core 3.0.
This page: https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/
Gives this example using a ...
1
vote
1
answer
514
views
.NET Core 3.1 - Ajax OnGet and return objects using NEW System.Text.Json
I stumbled across this issue today for the first time when trying to return an array of objects from a LINQ query that contains a foreign key field. The move by Microsoft away Newtonsoft JSON Library ...
104
votes
5
answers
69k
views
ASP.NET MVC Core API Serialize Enums to String
How to serialize Enum fields to String instead of an Int in ASP.NET MVC Core 3.0? I'm not able to do it the old way.
services.AddMvc().AddJsonOptions(opts =>
{
opts.JsonSerializerOptions....
25
votes
1
answer
20k
views
Modifying a JSON file using System.Text.Json
I know you can do this easily with Newtonsoft. As I am working with .NET Core 3.0, however, I am trying to use the new methods for interacting with JSON files —i.e., System.Text.Json—and I refuse to ...
1
vote
1
answer
825
views
Deserializing JSON to DateTime property throws exception
I'm trying to deserialize the following JSON:
{
"Anriss": "SomeAnriss",
"ArtikelId": 123123,
"Image": null,
"KanalId": 101,
"MediumName": "SomeMediumName",
"PublikationsDatum":...
1
vote
1
answer
828
views
System.Text.Json JsonRequired Replacement in web api
I've had a good google but can't seem to find a replacement for Json.Net's annotations in System.Text.Json (specifically JsonRequired).
Is the new Microsoft framework not really a replacement for ...
15
votes
3
answers
67k
views
The JSON value could not be converted to System.Nullable[System.Int32]
I updated an ASP.NET Core 2.2 API to ASP.NET Core 3.0 and I am using System.Json:
services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddJsonOptions(x => {})
I ...
2
votes
2
answers
4k
views
Json.Net JsonConstructor attribute alternative for System.Text.Json
In Json.Net we have JsonConstructor attribute in order to instruct deserializer that should use the constructor to create the object.
Is there alternative in System.Text.Json?
3
votes
2
answers
2k
views
using System.Text.JSON with ASP.NET Core 3: decide about pretty JSON output on endpoint?
With ASP.NET Core 3 and System.Text.Json you can return pretty formatted JSON by adding
services.AddControllers().AddJsonOptions(
options => options.JsonSerializerOptions.WriteIndented = true);
...
7
votes
0
answers
1k
views
Disable System.Text.Json on Web API on .NET Core 3.0
I would like explicitly use legacy Newtonsoft.Json library for serialization/deserialization on .NET Core Web API 3.0.0. No mater what I do, always System.Text.Json is involved and custom Newtonsoft's ...
64
votes
10
answers
64k
views
Ignore property when null using the new Net Core 3.0 Json
When using JSON.Net in ASP.Net Core 2.2 I was able to ignore a property when its value was null when serializing to JSON:
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public DateTime? ...