14,092 questions
2
votes
1
answer
129
views
Newtonsoft for ISerializable classes with a reference loop - use GetObjectData for serialization and ordinary constructor for deserialization
I have a couple of ISerializable classes (simplified):
internal interface IBase : ISerializable
{
int Number { get; }
}
internal interface ITable : IBase
{
ISection Section { get; }
}
[...
3
votes
1
answer
148
views
Deserialization via Newtonsoft for classes with a reference loop, private constructors and private/internal properties setters
I have a couple of classes (simplified):
internal interface ITable
{
int Number { get; }
ISection Section { get; }
}
internal class Table : ITable
{
public int Number { get; private init; ...
-1
votes
0
answers
84
views
ASP.NET Core Web API: LinkCollectionWrapper<T>.Values always null in JSON despite being populated
I'm building a HATEOAS implementation in ASP.NET Core using a LinkCollectionWrapper<T> class that wraps a collection of entities and stores links.
My classes look like this:
public class ...
0
votes
0
answers
69
views
How to specify a field of default value to be always included individually in yaml definition for a C# OpenAPI service
I have a C# OpenAPI service, which uses dotnet-nswag.dll openapi2cscontroller to generate the Controller code based on a yaml definition.
In Program.cs,
builder.Services.AddNewstonsoftJson(
...
0
votes
1
answer
81
views
Json Serialization - Work around for ExpandableObjectConverter [duplicate]
I'm writing code for .NET 8.
Given this class Sample:
[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]
[DataContract]
public class Sample
{
[DataMember]
public int SampleId {...
1
vote
1
answer
88
views
Coding a Nested JSON object using Newtonsoft.Json
I am attempting to code a nested JSON object for an upload API endpoint. I am having issues forming the code for the nested object. When I call the endpoint to post the data to their site, I get a ...
0
votes
1
answer
139
views
Deserializing array of objects to concrete .NET types using Newtonsoft
I have a couple of classes (simplified):
internal class OrderItem
{
public string Name { get; set; }
public Order Order { get; set; }
}
internal class Order
{
public IReadOnlyList<...
0
votes
0
answers
65
views
Resolving conflicts between attributes and relationships in JsonApiSerializer
I'm working on a C# program that will integrate with Planning Center's json-api compliant API (docs can be found here.) For (de)serialization purposes, I'm using the JsonApiSerializer library, which ...
0
votes
1
answer
120
views
Serializing and deserializing inherited class
So i have WeaponStats class that contains one of classes that inherit from IDamageType.
Fire is empty bacause i didn't receive anything back from game designer and its still empty. But i can add ...
2
votes
1
answer
158
views
Deserialize complex JSON with data in keys
I am building an editor script for Unity to import a complicated blueprint JSON asset extracted from another game engine. Some of this data is stored in the keys, meaning I cannot follow a typical ...
2
votes
0
answers
74
views
Why does xUnit consider that a JToken is equal to all the numbers? [duplicate]
I'm using .NET9.0.
MRE:
public class JTokenEqualityTests
{
[Fact]
public void IntVsJToken_AssertEqual_ShouldFailButDoesnt()
{
int original = 42;
JToken token = JToken....
3
votes
0
answers
103
views
JSchemaValidatingReader - OOM when handling large tokens
We have encountered some memory issues when validating JSON.
We are using:
Newtensoft.Json v 13.0.3
Newtonsoft.Json.Schema 4.0.1
.NET 9.0.304
For validation we have this code:
var validationResult = ...
2
votes
0
answers
78
views
Deserialization to different classes [duplicate]
I'm poking around the documentation, but I'd also want to reach out each to y'all incase there's a known solution to my issue or deserializing a json into different classes.
I have items of different ...
0
votes
1
answer
152
views
Why is `JArray.ToObject<List<T>>` faster than `JArray.ToObject<T[]>`
We are trying to micro-optimise some parts of our production code and I was expecting that using Arrays would generally be better than Lists in .NET, and most of the times, my benchmarks indicate that....
2
votes
2
answers
129
views
Serialize/deserialize a ReferenceLoop of ISerializable objects with Newtonsoft.JSON (Json.NET)
Preamble: I know about ISerializable deprecation. We have to use it because we have massive legacy codebase for IPC (that uses this interface). We are migrating from .NET Remoting to a crossplatform ...