All Questions
Tagged with .net serialization
2,432
questions
1
vote
2
answers
26
views
How to set a JsonSerializerOptions globally for my httpClient.GetFromJsonAsync<T> calls
In my ASP.NET web API I have httpClient which call GetFromJsonAsync:
var jsonSerializerOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
};
...
0
votes
0
answers
17
views
System.Net.Http.Json is not taking Fields into account when serializing or deserializing to JSON [duplicate]
When trying to Serialize a model which has data stored in fields System.Net.Http.Json is outputting an empty JSON Object. It works only when I use property with getters and setters.
I tried looking ...
0
votes
0
answers
45
views
Alternative For Type.IsSerializable
We used in an application
if (!value!.GetType().IsSerializable)
return;
In the meantime the IsSerializable property is obsolete (Formatter-based serialization is obsolete and should not be used.)....
1
vote
1
answer
34
views
System.Text.Json.JsonSerializer does not overwrite existing file fully when using file stream
Consider the following code:
internal class Program
{
static async Task Main(string[] args)
{
var t = new Thing() { Name = "Some Long Name" };
string path = @"c:\...
1
vote
1
answer
71
views
C# - How can I (de)serialize internal classes (from)to XML with attributes?
I want to (de)serialize internal classes.
internal class Data
{
public string? Name { get; set; }
public string? Type { get; set; }
public List<DataWithAttribute> DataList { get; set;...
1
vote
0
answers
46
views
Deserialize Object in .net standard which was serialized in .NET framework
I have a client-server application which runs on .NET Framework v4.8. Now I've migrated parts of the application to .NET Standard 2.0. The .NET Standard parts are used by the client and the server.
...
1
vote
1
answer
86
views
sgen/microsoft.xmlserializer.generator fails to generate
I've created a new .NET Standard 2.0 project and added the following class:
using System;
using System.Xml.Serialization;
namespace MyFunnyLib
{
[Serializable]
public class Foo
{
[...
0
votes
1
answer
117
views
The JSON property name for 'StatusCode' collides with another property
How can I support case-sensitive property names in System.Text.Json in .NET?
[JsonPropertyName("statusCode")]
public string? StatusCode { get; set; }
[JsonPropertyName("StatusCode"...
0
votes
0
answers
45
views
InvalidOperationException with System.Text.Json when using Rystem.OpenAi's ExecuteAsync()
Body:
Description
I am encountering a serialization error when attempting to execute a chat request using the Rystem.OpenAi library. The error occurs specifically when calling ExecuteAsync() on a ...
0
votes
0
answers
50
views
Utf8Json serializer custom formatter not working
I want to make custom formatter for utf8json serializer. Functionality is that if string property has value "null" it should deserialize it as null. And formatter should be enabled globally ...
0
votes
1
answer
113
views
I'm using System.Text.Json.Serialization, Why [JsonPropertyName] is ignored for query params
I'm using System.Text.Json.Serialization and I have a class for query. In this class, I customize the JsonPropertyName attribute to "site".
public class SearchQuery
{
[JsonPropertyName(&...
0
votes
3
answers
77
views
Convert JSON with various number of fields in .net
I have structure like this:
public enum Roles
{
ROLE_1,
ROLE_2,
ROLE_3,
...
ROLE_20
}
public enum Status
{
NONE,
ACTIVE,
REFUSE
...
}
Depend on user I can receive from API various number of roles in ...
0
votes
1
answer
66
views
Trouble in Deserializing from a JSON String(which contains special characters) in C#
I have the following JSON in C# :
string extractedText = " [
{
"mainQuestion": "Question 5: Attempt Any 2 [5 x 2 = 10]",
"question": "...
0
votes
0
answers
82
views
How to serialize int32 in little-endian order, and deserialize on both little-endian and big-endian architectures?
I serialize the integer anyway in little-endian order
public byte[] Serialize(int value)
{
return new byte[4]
{
(byte)value,
(byte)(value >> 8),
(byte)(value >&...
1
vote
1
answer
45
views
C# Custom Dictionary with JSON (de-)serialize
I have to create a C# class for a dynamic JSON I get from an external API. The json looks like this:
{
"id": "dataset0",
"properties": {
"createtime&...