/// <inheritdoc/> public override byte[] CourseToByteArray(ICourse course) { CourseWrapper wrapper = new CourseWrapper(course); JObject jObject = JObject.FromObject(wrapper, JsonSerializer.Create(CourseSerializerSettings)); jObject.Add("$serializerVersion", Version); // This line is required to undo the changes applied to the course. wrapper.GetCourse(); return(new UTF8Encoding().GetBytes(jObject.ToString())); }
/// <inheritdoc/> public override ICourse CourseFromByteArray(byte[] data) { string stringData = new UTF8Encoding().GetString(data); JObject dataObject = JsonConvert.DeserializeObject <JObject>(stringData, CourseSerializerSettings); // Check if course was serialized with version 1 int version = dataObject.GetValue("$serializerVersion").ToObject <int>(); if (version == 1) { return(base.CourseFromByteArray(data)); } CourseWrapper wrapper = Deserialize <CourseWrapper>(data, CourseSerializerSettings); return(wrapper.GetCourse()); }