1

I need to serialize,deserialize,read,write a list of objects Employee. I tried using json.net but there were issues with it. Any advice?

class Employee
        {
            public string First_name { get; set; }
            public string Last_name { get; set; }
            public string Gender { get; set; }
            public int Pin { get; set; }
            public bool Active { get; set; }
            public bool SignInStatus { get; set; }
            public string Department { get; set; }
            public DateTime SignInTime { get; set; }
            public DateTime SignOutTime { get; set; }
            public DateTime BreakSignInTime { get; set; }
            public DateTime BreakSignOutTime { get; set; }
            public double BreakTimeElasped { get; set; }
            public bool BreakStatus { get; set; }
            public double SessionTimeElasped { get; set; }


            public static List<Employee> EmployeeDatabase = new List<Employee>();

Constructor:

            public Employee(string firstname, string lastname, int pin, string department, string gender, bool active)
            {
                this.First_name = firstname;
                this.Last_name = lastname;
                this.Pin = pin;
                this.Department = department;
                this.Gender = gender;
                this.Active = active;


            }

Method to create objects and add to list

            public static void CreateNewEmployee(string firstname, string lastname, int pin, string department, string gender, bool active)
            {



                if (Employee.EmployeeDatabase.Count > 0)
                {

                    EmployeeDatabase.Add(new Employee(firstname, lastname, pin, department, gender, active));
                    int indexz = EmployeeDatabase.Count - 1;

                }
                else
                    EmployeeDatabase.Add(new Employee(firstname, lastname, pin, department, gender, active))

;

Daniel
  • 103
  • 1
  • 1
  • 6
  • 2
    Possible duplicate of [Serializing a list to JSON](https://stackoverflow.com/questions/9110724/serializing-a-list-to-json) – mjwills Jun 07 '18 at 03:57
  • Some of the variables would be not be changeable. It would go through the constructor each time and change some of the variables to default. – Daniel Jun 07 '18 at 03:57
  • It would be awesome if you could provide a [mcve] using json serialisation with sample inputs and expected results based on those inputs. – mjwills Jun 07 '18 at 03:59
  • "Best" might depend on what you want to do with it. Back in .Net 1.0 days I used the BinaryFormatter a lot, it's hidden in the System.Runtime.Serialization.Formatters.Binary namespace. If I remember right it doesn't need a constructor. It's not quite as smart as the Java one, and the content is not human readable. But it's quick and easy to use as long as you know what you're doing. I understand the BinaryFormatter didn't make it to .Net Core but there would be other formatters there you could probably use. – Swanny Jun 07 '18 at 04:30

0 Answers0