|
17 | 17 | class Contact(MappingConstructible["Contact"], JsonSerializable): |
18 | 18 | def __init__( |
19 | 19 | self, |
20 | | - name: str, |
21 | | - organization: str, |
22 | | - position: str | None = "", |
| 20 | + name: str | None = None, |
| 21 | + organization: str | None = None, |
| 22 | + position: str | None = None, |
23 | 23 | links: list[dict[str, Any]] | None = None, |
24 | | - contactInstructions: str | None = "", |
25 | | - roles: list[str] = None, |
| 24 | + contactInstructions: str | None = None, |
| 25 | + roles: list[str] | None = None, |
26 | 26 | ): |
27 | 27 | self.name = name |
28 | 28 | self.organization = organization |
29 | 29 | self.position = position |
30 | | - self.links = links or [] |
| 30 | + self.links = links |
31 | 31 | self.contactInstructions = contactInstructions |
32 | | - self.roles = roles or ["principal investigator"] |
| 32 | + self.roles = roles |
| 33 | + |
| 34 | + def to_dict(self, value_name: str | None = None) -> dict[str, JsonValue]: |
| 35 | + """Serialize to JSON, dropping None values.""" |
| 36 | + data = { |
| 37 | + "name": self.name, |
| 38 | + "organization": self.organization, |
| 39 | + "position": self.position, |
| 40 | + "links": self.links, |
| 41 | + "contactInstructions": self.contactInstructions, |
| 42 | + "roles": self.roles, |
| 43 | + } |
| 44 | + # keep only explicitly set fields |
| 45 | + return {k: v for k, v in data.items() if v is not None} |
33 | 46 |
|
34 | 47 |
|
35 | 48 | class ThemeConcept(MappingConstructible["ThemeConcept"], JsonSerializable): |
|
0 commit comments