hug icon indicating copy to clipboard operation
hug copied to clipboard

Document how to extend json serialization

Open Omniflux opened this issue 6 years ago • 0 comments

Not sure where to add this in the documentation, but if you get an error such as this when trying to output

TypeError: Type <class 'uuid.UUID'> not serializable

You can add new types to the json converter like this

from uuid import UUID
@hug.output_format.json_convert(UUID)
def uuid_stringable(item):
    return str(item)

Omniflux avatar Jan 05 '19 19:01 Omniflux