Aggiunto modulo per la conversione degli oggetti in JSON

This commit is contained in:
Fabio Scotto di Santolo
2021-06-24 20:59:13 +02:00
parent a3e5229bfa
commit b53629ae6e
5 changed files with 15 additions and 9 deletions

View File

@@ -19,11 +19,11 @@ class Department:
def location_id(self) -> Location:
return self.__location
def to_json(self):
def __json__(self):
return {
'department_id': self.__department_id,
'name': self.__name,
'location': self.__location.to_json() if self.__location is not None else None
'location': self.__location if self.__location is not None else None
}
def __str__(self):

View File

@@ -62,14 +62,14 @@ class Employee(Person):
def manager_id(self) -> int:
return self.__manager_id
def to_json(self):
def __json__(self):
return {
'employee_id': self.__employee_id,
'first_name': self.first_name,
'last_name': self.last_name,
'email': self.__email,
'hire_date': f"{self.__hire_date: %Y-%m-%d}",
'department': self.__department.to_json() if self.__department is not None else None,
'hire_date': self.__hire_date,
'department': self.__department if self.__department is not None else None,
'job_id': self.__job_id,
'salary': f"{self.__salary:,.2f}",
'manager_id': self.__manager_id

View File

@@ -32,7 +32,7 @@ class Location:
def country_id(self) -> int:
return self.__country_id
def to_json(self):
def __json__(self):
return {
'location_id': self.__location_id,
'street_address': self.__street_address,