Questions tagged [system.text.json]
System.Text.Json is the built-in JSON facilities added in .NET Core 3.0.
system.text.json
1,169
questions
0
votes
0
answers
23
views
How to read `DeclaringType` from `JsonPropertyTypeInfo` in System.Text.Json?
I want to customize serialization based on the type of the property. To do that I would like to read DeclaringType from JsonPropertyInfo. This is an example from Microsoft documentation on how to ...
1
vote
0
answers
61
views
do not serialize empty collections (and handle accordingly in deserialization)
I have a bunch of POCOs that can be (de-)serialized from/to json. A lot of content is collections. I want the serialized JSON to only contain a specific property if its collection is not empty (...
0
votes
2
answers
51
views
Problem with Serializing JSON to CamelCase in C#
I am trying to serialize a JSON string to convert property names to camelCase using the System.Text.Json library. However, I still get the outcome with PascalCase.
Here is my code:
var stringJson = &...
0
votes
0
answers
56
views
Serializer not returning expected output in .NET Core
I have a controller which returns Task<ActionResult> which internally returns a List<CustomObjectA>.
The structure of CustomObjectA is like this:
[DataContract]
public class CustomObjectA
{...
0
votes
0
answers
25
views
Source Generator not running when using System.Text.Json.JsonSerializer
I have a large list of types that I need to have basic CRUD services and editors for. I intend to use Source Generators to create all of these classes at compile time based on a json file containing ...
1
vote
0
answers
35
views
How to resolve the generic form of a JsonConverter in System.Text.Json
I know that this issue is more a question of the limitations of C# generics than it is a question about .NET Core (8.0) JSON Serialization but it is driving me crazy.
When getting 'underneath the hood'...
1
vote
1
answer
51
views
From a minimal ASP.NET Core Web API how do I return a JObject while maintaining the nested elements?
I am building a minimal ASP.NET Core Web API. One of my endpoints needs to return data contained in a JObject. This JObject represents a complex nested data structure. What I am finding is that the ...
0
votes
0
answers
29
views
System.Text.Json ecapes single quotes by design [duplicate]
I know that System.Text.Json escapes single quotes by design, but the examples for how to allow certain characters to not be escaped from MS Docs doesn't work for me as I want to keep single quotes in ...
0
votes
1
answer
67
views
Why is using JsonSerializer.DeserializeAsyncEnumerable to deserialize a 1GB file resulting in 2GB+ memory allocation?
I need to deserialize a 1GB json file one element at a time in a streaming fashion and after doing some reading found JsonSerializer.DeserializeAsyncEnumerable to enable this while also keeping the ...
2
votes
1
answer
73
views
Enforce the use of Utf8JsonReader.ValueSequence for test purposes
I wrote my own BigIntegerConverter for JSON serialization/deserialization (.Net System.Text.Json)
In the Read method I checked if ValueSequence is used
...
string stringValue;
if (reader....
0
votes
0
answers
66
views
In C#, why does System.Text.Json.JsonSerializer.Serialize fail to serialize correctly when using dependency injection (interfaces)? [duplicate]
Why does the following write out only "{}"?
var myLogin = new TestLogin
{
UserName = "[email protected]",
Password = "Pass123"
};
Console.WriteLine(System.Text.Json....
0
votes
0
answers
40
views
Ban entire namespace with BannedApiAnalyzers
I am trying to ban the usage of Newtonsoft.Json package in my codebase, and I am trying to use the BannedApiAnalyzers Nuget package (latest stable version, 3.3.4).
My problem is that while I am able ...
0
votes
1
answer
38
views
Trying to deserialise and the JSON value could not be converted to class(?)
very newbie programmer here trying to learn C#. I'm trying to deserialise a JSON file and then print the values inside. However, I'm met with a Jsonexception in the form of cannot be converted to the ...
0
votes
1
answer
126
views
Use System.Text.Json converters with JsonTypeInfo for AOT
My .NET 8 application is AOT-compiled so it needs to use JsonTypeInfo and cannot use reflection-based serialisation. Now I also want to use the converter feature to store objects differently than in ...
0
votes
1
answer
54
views
How to transform "Types" a List<string> foo class property into a SQL Server table [Types](FooID int, name nvarchar) with Entity Framework Core
I received a JSON from a REST API, deserialized into a list of foo objects:
class Foo
{
public int Id { get; set; }
public string Name { get; set; }
...
public List<string> Types ...