Skip to main content
Filter by
Sorted by
Tagged with
1 vote
3 answers
76 views

I'm trying to migrate a simple app with a basic API to crunch numbers to generate a load, to a single-file application as a proof of concept. generate-load-server.cs: #! /usr/bin/env dotnet run #:sdk ...
Jeff Mercado's user avatar
1 vote
2 answers
154 views

I am developing a layered .NET project with API, BLL, DAL, and UI layers. The UI layer calls the API using a generic API repository built with HttpClient. My project structure is roughly like this: ...
NEX's user avatar
  • 13
1 vote
1 answer
101 views

I'm testing a method that reads a JSON file. So in the setup, I first create said JSON file, like this: string pathOfRelevantStuff = "path"; string fileOfRelevantStuff = Path.Combine(...
Jean-David Lanz's user avatar
0 votes
0 answers
67 views

When I run System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>> all values are converted to JsonElement, instead of the actual value. I expect numbers to be converted to ...
Eric's user avatar
  • 2,440
1 vote
1 answer
196 views

I would like to be tolerant if the JSON payload contains a type my app doesn't know about. Ideally I would like to get information about the errors along with the deserialized object, but at a minimum ...
default.kramer's user avatar
2 votes
1 answer
129 views

I have the following C# code in a .NET 9 project that will be AOT-compiled: var deviceEntries = new JsonArray(); foreach (string deviceId in deviceIds) { var deviceEntry = new JsonObject { ...
ygoe's user avatar
  • 20.9k
1 vote
1 answer
277 views

I am binding an OpenAPI 3.0 JSON file in my C# project with .NET Framework 4.8. While doing this, I want to adjust the .json configuration to make the code generated using OpenAPI code generator use ...
Khamis Abuelkomboz's user avatar
1 vote
1 answer
121 views

I want to create a JSON deserializer that returns a specific type. The JSON can be either in a format that marches SpecificOne or SpecificTwo. We only know that at runtime. Once we deserialize it, I ...
riki's user avatar
  • 2,445
Advice
0 votes
2 replies
298 views

I'm trying to do a polymorphic deserialization using System.Text.Json in net-8.0. Here is my schema. [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Manager)...
fingers10's user avatar
  • 8,519
1 vote
2 answers
160 views

I want to serialize a nested JSON structure using System.Text.Json into regular C# classes, but I have a specific case where I want a single property of a nested object instead of the full object ...
Max Play's user avatar
  • 4,099
-2 votes
3 answers
385 views

I am trying to deserialize a JSON string in C#: JsonObject json = JsonSerializer.Deserialize<JsonObject> ("{\"columnsperrow\":\"1\",\"columnwidths\":[400.0]...
SPlatten's user avatar
  • 5,915
2 votes
2 answers
175 views

This is a follow up question to the Ignore boolean property = true in JSON serialization. I have a record with multiple bool properties, some of them having default value true and some false: private ...
Theodor Zoulias's user avatar
2 votes
1 answer
94 views

I have a record with a bool property that has default value = true: private record MyRecord() { public bool BoolProperty { get; init; } = true; } I want to ignore the "BoolProperty":...
Theodor Zoulias's user avatar
1 vote
2 answers
203 views

I have a property in an object; if its value is string.Empty, I don't want this property in the serialized JSON. I have seen this solution: public class JsonEmptyString : JsonConverter<string> { ...
FoxScully's user avatar
  • 111
0 votes
2 answers
131 views

Use case: I want to write a JsonConverter for a generic type like this, but I cannot apply it to the type itself: public class EditingModelConverter<T> : JsonConverter<EditingModel<T>&...
Luke Vo's user avatar
  • 21.8k
2 votes
1 answer
94 views

I want to create a custom attribute that basically does the same as [JsonIgnore] from System.Text.Json, but has a different name. The reason for that is that we have virtual properties, that among ...
user21526533's user avatar
6 votes
1 answer
313 views

We are having some issues deserialising classes with Quaternion properties. We are seeing very odd behaviour. The Quaternions deserialise correctly (we can do a custom JsonConverter to confirm the ...
Iain Stanford's user avatar
2 votes
1 answer
156 views

I'm deserializing interfaces mapped to usual classes with a custom IJsonTypeInfoResolver. The resolver looks similar to this: public class InterfaceMappingResolver : IJsonTypeInfoResolver { ...
tris's user avatar
  • 1,129
1 vote
0 answers
69 views

We have a class as shown below: public class KeyVal<Key, Val> { public Key Id { get; set; } public Val Text { get; set; } public KeyVal() { } public KeyVal(Key key, Val ...
user2981411's user avatar
1 vote
0 answers
64 views

Imagine that you have marked all sensitive data with the [Secret] attribute throughout your project and want it all to be deleted when you save your models to disk, i.e. the following program using ...
eggor's user avatar
  • 73
1 vote
1 answer
135 views

Consider these model classes: [JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")] [JsonDerivedType(typeof(A), typeDiscriminator: nameof(A))] [JsonDerivedType(typeof(B), ...
aepot's user avatar
  • 4,906
1 vote
0 answers
315 views

I'm migrating from Newtonsoft.Json to System.Text.Json in my Unity project due to its reported benefits: lighter memory footprint and better performance through source generation, which should ...
Layth Rachwani's user avatar
1 vote
1 answer
490 views

I'm currently using the following code to set up a System.Text.Json JsonSerializerOptions object that alphabetizes properties upon serialization: public static readonly JsonSerializerOptions ...
Chaosed0's user avatar
  • 981
7 votes
2 answers
1k views

I've got a simple type: public class Example { [JsonIgnore] public required string RequiredButDontSerialize {get;init;} public string AnotherPropertyWhatever {get;init;} } that causes System....
Moose Morals's user avatar
  • 1,738
0 votes
0 answers
80 views

Background I have an ASP.NET Core 9 Web API project with [nullable reference types] enabled (<Nullable>enable</Nullable>). In my request DTOs, I declare certain properties as non‑nullable, ...
Tom's user avatar
  • 497
0 votes
1 answer
129 views

I'm currently using .NET Framework 4.7 along with MSTest (all packages are up to date). I'm trying to deserialize a JSON string using System.Text.Json as shown here: using System.Text.Json; private ...
undrgng's user avatar
0 votes
0 answers
75 views

I have a basic ASP.NET Web API project. When I send a request, the serialization is done using System.Text.Json. However, when I send a non-valid json, for example text instead of number, it returns a ...
pietro's user avatar
  • 231
2 votes
2 answers
146 views

When serializing a complex record in an UWP application, it works fine in debug mode, but in release mode, when application is packaged using Windows application packaging project, the JsonSerializer ...
gPok's user avatar
  • 31
2 votes
0 answers
51 views

I am duplicating this question, except applying it to System.Text.Json: How do you limit indentation depth when serializing with Newtonsoft.Json. When serializing an object using System.Text.Json, is ...
Frank Schwieterman's user avatar
1 vote
1 answer
66 views

We have a local Web API used for internal clients to retrieve data. We use application/json to transport the data across the Web API. The retrieved JSON data has a simple structured class 'Response'. ...
Andrew Northcote's user avatar
0 votes
1 answer
173 views

I am trying to use System.Text.Json library for performance improvement. When I am trying to convert it, System.Text.Json is not able to deserialize the object but Newtonsoft.Json able to do so. How ...
hasan.in's user avatar
  • 733
1 vote
1 answer
138 views

I'm deserializing a series of objects from a third party source. There are a number of different formats, but once I have deserialized them, I want them all to have a common interface. So I have my ...
PaulH567's user avatar
  • 329
-5 votes
1 answer
173 views

I have a System.Text.JsonElement with about 100 elements inside. I know of EnumerateArray(), but is there a way to do this backwards, meaning: Start at the last element of the list and enumerate until ...
swrk's user avatar
  • 23
5 votes
2 answers
448 views

I have my JSON serialised into a single line. How can I load it, remove a property, and then serialise it to a single line again? internal class Program { static void Main(string[] args) { ...
jessejbweld's user avatar
1 vote
1 answer
203 views

I'm implementing a custom JsonConverter that handles nullable types. Specifically, it turns empty strings and empty arrays into null. I've managed to piece together this: (with help from here) public ...
dave's user avatar
  • 61
1 vote
2 answers
309 views

Given a sample class structure like this public class ParentClass { public int ParentProperty1 { get; set; } public int ParentProperty2 { get; set; } } public class ChildClass: ParentClass { ...
PaulH567's user avatar
  • 329
2 votes
3 answers
219 views

I want to create a JsonSerializable class, that I can inherit from. See this code: using System; using System.Text.Json; using System.Text.Json.Serialization; public interface IJson { string ...
Bart Friederichs's user avatar
2 votes
1 answer
315 views

In my production environment while running a console application wrapped using an installer I get this error: System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, ...
Mead Ahmed Fahim's user avatar
0 votes
1 answer
229 views

I'm trying to use JsonSerializer in a simple .NET 8.0 console application, but I'm getting the error: The type or namespace name 'JsonSerializer' could not be found (are you missing a using directive ...
user avatar
0 votes
1 answer
95 views

I have built a C# library to make queries on Salesforce using Web Calls. This is an example of implementation: var myQuery = new SalesForceQueryBuilder<MyCoustomUnicornEntity>() ...
FrankOfTheScience's user avatar
0 votes
0 answers
34 views

I'm upgrading .NET to version 8 and a “problem” is occurring that wasn't happening before. I have a class A that has a field of type JObject from the Newtonsoft.Json library and this field uses the ...
Vagner Wentz's user avatar
0 votes
1 answer
77 views

I'm wanting to only expose a list as ReadOnly but it's, but while trying to accomodate that for Deserialization, it's not currently working. Firstly, to confirm Serialization: { "StartTime"...
MrGreggles's user avatar
  • 6,205
5 votes
1 answer
252 views

With .NET 8, using System.Text.Json, I can serialize/deserialize a List<T>. I can also serialize an object with a property of type List<T>. However, I cannot deserialize that object. Here ...
Kairei's user avatar
  • 131
1 vote
1 answer
119 views

I have the following class: public class DeviceInfo { public string? ip { get; set; } public string? deviceKey { get; set; } public long time { get; set; } public string? version { get;...
jstuardo's user avatar
  • 4,564
2 votes
3 answers
348 views

I'm trying to convert this line: builder.Services .AddControllers() .AddNewtonsoftJson(o => o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); ...
KeithViking's user avatar
1 vote
1 answer
2k views

I am getting the following exception when I am trying to serialize a double that has the value NaN, via JsonConverter The exception is: System.ArgumentException: '.NET number values such as positive ...
Liviu Sosu's user avatar
  • 1,609
1 vote
0 answers
103 views

I setup my poly serialization with one abstract class and couple concrete classes. However the property which I want to use as a discriminator is already present in a base class as a string. Now when ...
vmachacek's user avatar
  • 583
4 votes
2 answers
768 views

For example, I have a class that derives from ObservableValidator and my resulting serialization then includes HasErrors. I want to only include my derived class's properties and don't have access to ...
azulBonnet's user avatar
0 votes
0 answers
98 views

I have the following ASP.NET Core Web API endpoint. This endpoint is auto-generated through a workflow that uses a TypeSpec definition, which is then converted to OpenAPI and then to an ASP.NET Core ...
André Reichelt's user avatar
1 vote
1 answer
396 views

I am getting an exception: > System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: TypeInfoResolver '...
Ricardo Peres's user avatar

1
2 3 4 5
26