✅ Get this error while trying to Deserialize object
This is an error I get. I am not even sure what part of code to send, which would cause an issue.
6 Replies
can you show the $code for AnimationTesting.Models.Room?
in particular it sounds like STJ is trying to use constructor deserialization
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/as detailed here https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/immutability?pivots=dotnet-7-0#immutable-types-and-records
How to use immutable types and non-public accessors with System.Tex...
Learn how to use immutable types and non-public accessors while serializing to and deserializing from JSON in .NET.
There are objects of other classes inside
Room
class. Should all of them jave [JsonConstructor]
?you only need JsonConstructor if there are multiple parameterized constructors on the class
For a class, if the only constructor is a parameterized one, that constructor will be used. For a struct, or a class with multiple constructors, specify the one to use by applying the [JsonConstructor] attribute. When the attribute is not used, a public parameterless constructor is always used if present.
thanks for help. My classes are too complicated to solve this problem that simply. I will create json models for each.