I have a strange issue, I have a model class which looks like this
public class Person
{
public string FirstName{get;set;}
public string LastName{get;set;}
[JsonIgnore]
[TextBlob("ApartmentBlobbed")]
public Apartment Apartment{get;set;}
[JsonIgnore]
public string ApartmentBlobbed{get;set;}
public string Exception
{
get
{
return Apartment.Exception;
}
set
{
Apartment.Exception = value;
}
}
}
public class Apartment
{
public string RoomNumber{get;set;}
public string BuildingNumber{get;set;}
public string Exception{get;set;}
}
I have a POST API call which only requires FirstName and LastName of Person object hence I have inserted the attribute JsonIgnore for the Apartment Object. If there occurs any exception then I need the Apartment object's exception to be set. As it is the same object which is being used in the UI.
Now the problem Since the API is called at some point in time, the Person object is saved in the database. When I retrieve the object of Person for API call, my Apartment object is null and hence the exception is also null.
REASON: Due to the JsonIgnore being set. SQLite uses NewtonSoft to serialize/Deserialize the objects.
Question:
How can I save the object with JsonIgnore and have the API call only with FirstName and LastName values, and if any exception occurs then I can set the Exception to the Apartment Exception.