using System.Text.Json; using System.Text.Json.Serialization; namespace Library; public class Employee { public string Id { get; set; } public string Code { get; set; } public string Surname { get; set; } public string Forename { get; set; } public string Email { get; set; } public string Phone { get; set; } public string Street { get; set; } public string City { get; set; } public string Postcode { get; set; } public string Country { get; set; } public string Department { get; set; } public string Position { get; set; } public EmployeeState EmployeeState { get; set; } public Employee() { } public Employee(string code, string surname, string forename, string email) { Id = Guid.NewGuid().ToString(); Code = code; Surname = surname; Forename = forename; Email = email; } /// /// Serialisiert dieses Employee-Objekt in einen JSON-String (nur öffentliche Eigenschaften). /// public string ToJson() { var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; return JsonSerializer.Serialize(this, options); } /// /// Deserialisiert aus dem JSON-String ein neues Employee-Objekt (öffentliche Eigenschaften). /// public static Employee FromJson(string json) { var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; return JsonSerializer.Deserialize(json, options) ?? throw new InvalidOperationException("Deserialization to Employee failed."); } }