I have the following code:
var model = new
{
Name = "Alexander"
};
var serializedModel = JsonSerializer.Serialize(model);
var deserializedModel = JsonSerializer.Deserialize<object>(serializedModel);
var name = deserializedModel!.GetType().GetProperty("Name");
The name variable is null as the "Name" property doesn't seem to exist. I do not have the model object when deserializing but just the JSON string.
I have tried using JsonConvert.DeserializeObject(serializedModel)
from Newtonsoft and that seems to be working fine. However, I want to use System.Text.Json. Also, I have to use .GetType().GetProperty(...)
as it's done like that in the external library I'm passing the deserialized object to.