Skip to content

Add default callback to Encoder/encode #20

Closed

Description

@jcrist

To support serializing arbitrary objects, it'd be useful to add a default callback (mirroring the option in json.dumps, orjson.dumps, ...). If provided, this would be called on unsupported objects, and would be expected to return a supported object.

def default(obj: Any) -> Any:  # where the out Any is a supported type
    ...

This would allow for converting unsupported types into supported types lazily, as well as fancier things like serializing unsupported large objects out-of-band.

Activity

  1. jcrist commented on Feb 25, 2021

    @jcrist
    MemberAuthor
  2. jcrist commented on Feb 25, 2021

    @jcrist
    MemberAuthor

    See #21.

  3. jcrist commented on Feb 25, 2021

    @jcrist
    MemberAuthor

    This has now been released as part of 0.2.0, and is available on PyPI. Please let me know how it works out for you, or if you have any further requests/questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions