24 | | The basic mechanism for pyson is to look at the __init__ function of the class under serialization. |
25 | | The arguments in the __init__ function are matched to the json fields. |
26 | | The arguments in the __init__ must be fully typed, and these types are used to determine how to interpret the json content. |
| 24 | The basic mechanism for pyson is to look at the {{{__init__}}} function of the class under serialization. |
| 25 | The arguments in the {{{__init__}}} function are matched to the json fields. |
| 26 | The arguments in the {{{__init__}}} must be fully typed, and these types are used to determine how to interpret the json content. |
| 28 | === Deserialization |
| 29 | For Deserialization of a json object, it goes like this |
| 30 | * if the target class has @JsonSubtypes, |
| 31 | * check which the subclasses are and what their ID is. |
| 32 | * Determine the actual class contained in the json |
| 33 | * "unwrap" the json, so that we have the remaining json to deserialize the actual class |
| 34 | * If it's not a JsonSubtypes, then the actual class is the requested target class |
| 35 | * now that the actual class is known, |
| 36 | * the parameter names and param-classes from the {{{__init__}}} function of the actual class are taken |
| 37 | * for each of the parameters, recursively deserialize the json value for that parameter, using the param-class as targetclass. |
| 38 | * call the constructor of the target class, using the parsed json for each parameter |