static void Main(string[] args) { Student martin = new Student() { FirstName = "Martin", LastName = "Panovski", Age = 26, IsPartTime = false }; if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } if (!File.Exists(filePath)) { File.Create(filePath).Close(); } string martinString = Serializer.SerializeStudent(martin); ReaderWriter.WriteFile(filePath, martinString); string jsonStudent = ReaderWriter.ReadFile(filePath); Student deserializedStudent = Serializer.DeserializeStudent(jsonStudent); Console.WriteLine("This is deserialized student: "); Console.WriteLine($"{deserializedStudent.FirstName}"); Console.WriteLine($"{deserializedStudent.LastName}"); Console.WriteLine($"{deserializedStudent.Age}"); Console.WriteLine($"{deserializedStudent.IsPartTime}"); Console.ReadLine(); }
static void Main(string[] args) { Student martin = new Student { FirstName = "Martin", LastName = "Panovski", Age = 27, IsPartTime = true }; // Serialization of C# object string martinString = CustomJsonSerializer.SerializeStudent(martin); Console.WriteLine(martinString); // Deserialization of json string into C# object Student martinDeserialized = CustomJsonSerializer.DeserializeStudent(martinString); Console.WriteLine(martinDeserialized.FirstName); Console.WriteLine(martinDeserialized.LastName); Student petre = new Student { FirstName = "Petre", LastName = "Arsovski", Age = 25, IsPartTime = true }; CreateFolder(folderPath); CreateFile(filePath); string jsonStudent = CustomJsonSerializer.SerializeStudent(petre); ReaderWriter.WriteFile(filePath, jsonStudent); string studentFromFile = ReaderWriter.ReadFile(filePath); Student studentParsed = CustomJsonSerializer.DeserializeStudent(studentFromFile); Console.WriteLine($"Hello there this is the student read from the file: {studentParsed.FirstName}"); Console.ReadLine(); }