I've created an API endpoint that is receiving a List of objects. The 'AttributeValue' of the objects could be either a string or an int. Here is a generic version of my code:
public class b
{
public List<a> myList {get; set;} = new List<a>();
}
public class a
{
public object AttributeValue {get; set;}
}
The problem is, I need to know the original data type. When I check the type it tells me "System.Text.Json.JsonElement". I also tried something like the following:
if(b.myList[0].AttributeValue is int) { do something.. }
else if(b.myList[0].AttributeValue is string) {do something...}
else {throw error}
I always throw an error so I assume I am losing my original data type when I am deserializing. Any ideas what I can do?