I'm trying to serialize a C# object to a JSON object. Here's the code:
QuestionGroup group = DatabaseMethods.GetQuestionGroup(questionGroupID);
JavaScriptSerializer jSer = new JavaScriptSerializer();
string json = jSer.Serialize(group);
group
looks as expected after line 1. The third line never returns anything, and I can't step into the function; I can only look at metadata and it doesn't mention anything about this. I'm not getting an exception; it just...never...returns.
The object I'm passing it is a pretty beastly class that has children and grandchildren. It's an EF class; I don't know if that could somehow be messing with the JSON serializer. It's supposed to take any object so I don't see how that would; but who knows.
Here's the class, with some code removed for conciseness:
public class QuestionGroup
{
public Int32 QuestionGroupID { get; set; }
public Int32 Order { get; set; }
[Display(Name = "Path to File", Prompt = "Path to File")]
[DataType(DataType.Upload)]
[NotMapped]
public HttpPostedFileWrapper PathToFile { get; set; }
public String FileName { get; set; }
public virtual Image Image { get; set; }
public Int32? ImageID {get; set; }
public String Text { get; set; }
public DateTime WhenCreated { get; set; }
public Int32 CreatedBy { get; set; }
[NotMapped]
public Int32 MasteryCriteriaNumerator { get; set; }
[NotMapped]
public Int32 MasteryCriteriaDenominator { get; set; }
public Boolean TeacherAdministersToStudent { get; set; }
/*Foreign keys for associations*************************************************/
public Guid MasteryObjectiveID { get; set; }
/*Navigational properties for EF************************************************/
public MasteryObjective MasteryObjective {
get { return DAL.DatabaseMethods.GetMasteryObjective(MasteryObjectiveID); }
}
public List<Question> Questions{ get; set; }
public virtual List<Assessment> Assessments { get; set; }
public virtual List<MultipleChoiceResult> MultipleChoiceResults { get; set; }
// The full url to qg's image on rackspace
[NotMapped]
public String RackspaceFullURL { get { return GetRackspaceURL(QuestionGroupID, FileName); } }
private String GetRackspaceURL(Int32 QuestionGroup, String FileName)
{
//code removed
}
}