Say I have a class:
public class Cat
{
public int Hunger {get; set;}
public int Sleepiness {get; set;}
public int Usefullness {
get { throw new DivideByZeroException(); }
}
}
Is it possible to serialize it as below:
public ActionResult GetMyCat()
{
Cat c = new Cat()
{
Hunger = 10,
Sleepiness = 10
};
return Json(c);
}
I can't modify the "Cat" class. Can I have the MVC JSON Serializer ignore the error that one property threw, (if it threw an error) and just give me an empty/default value for that property?