How to ignore Property on JSON deserialization?
My Dto has Id property: public class ADto { public int Id { get; set; } public string Text { get; set; } } The Id is set by EF Core not by Frontend request, so I want to ignore…
My Dto has Id property: public class ADto { public int Id { get; set; } public string Text { get; set; } } The Id is set by EF Core not by Frontend request, so I want to ignore…
Having following classes: public class Person { public int Age { get; set; } } using System.Collections; using System.Text.Json.Serialization; namespace SerializeCustomEnumerable; public class Statistics<T> : IEnumerable<(int Year, T Value)> where T : new() { // Underlying structure where data are…
I'm sorry for the bad title but I really don't know how to put this any other way. The detailed problem is as follows: I have a .NET API with Controllers. I have a controller that has a reference to…
in my .NET 5 application I deserialize data using the System.Text.Json functions. This works for the most part. Except for one field in the received JSON document, which can contain a number array, a string array or a single string…
We had an ASP.NET Core 5 Web API backend alongside a ReactJS UI app. In startup we instantiated the json framework the following way: services.AddControllers() .AddNewtonsoftJson() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); It was working well alongside "JsonPropertyName" attributes, i.e.…
I have a .NET 6 program that needs to deserialize a JSON string value (returned by external API) into a .NET enum. The issue is that there are over 100 possible enum values (and more could be added without my…
I try to parse a response by the OSRM map matching service using the following code (here a .NET Fiddle too): namespace OsrmMapMatch { public class OsrmResponse { public string code; public OsrmLeg[] legs; } public class OsrmLeg { public…
I have a json string that has nested values: { "card": { "number": "411111111111111111", "expirationMonth": null, "expirationYear": null, "securityCode": null } } I want to remove expirationMonth, expirationYear, securityCode so that only card: number remain. but I can't find any…
Let's say I am expecting a simple JSON response from an API like so: { "message": "Source: ", "incomingUrl": "https://10.1.1/api/echo", "incomingHeadersCount": 21, "apiVersion": "1.0" } I can use JsonNode to parse it and output the lines. This requires me to…
What would be the best way of making STJ deserialize correctly for cases where the type of the constructor parameter does not match the type of the property with a matching name? Consider the following code sample: using System.Text.Json; string…