serialize_unknown
No overview available.
def serialize_unknown(
obj: Any
) - > Union[dict, str]
Converts non-standard Python objects into JSON-serializable formats by attempting to access their internal dictionary or converting them to strings. Use this as a fallback handler for JSON encoders to prevent serialization errors when encountering custom class instances.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | Any | The object instance that the standard JSON encoder is unable to process. |
Returns
| Type | Description |
|---|---|
Union[dict, str] | A dictionary representation of the object's attributes if available, otherwise the string representation of the object. |