Just found this very neat way in Go
to define the correlating json key
for a class attribute, where the former is the class attribute definition and the latter what key
it translates to in a json
.
This approach allows to auto-magically serialize a class to a given json-structure (e.g. when you're dealing with many different REST APIs that expect different payloads) but also allows translating a json
payload to a class instance.
Any way of achieving something similar with Python? I so far always tried to map my attribute names to the json
structure, but it becomes an impractical mess when the API e.g. deals with camelCase
or some abbreviations instead.
type EmailpkiSmime struct {
Locked string `json:"_locked"`
ObjectType string `json:"_type"`
Reference string `json:"_ref"`
Cert string `json:"cert"`
Comment string `json:"comment"`
Dn string `json:"dn"`
// Domaincert default value is false
Domaincert bool `json:"domaincert"`
Emails []string `json:"emails"`
Expires string `json:"expires"`
Fingerprint string `json:"fingerprint"`
// Key default value is ""
Key string `json:"key"`
Name string `json:"name"`
// Realname default value is ""
Realname string `json:"realname"`
// Trust default value is false
Trust bool `json:"trust"`
}