orjson icon indicating copy to clipboard operation
orjson copied to clipboard

Default to str() for Unknown objects as keys when using `OPT_NON_STR_KEYS`

Open timkpaine opened this issue 2 years ago • 0 comments

This is a rebase of #438, which was closed as stale.

When using passing a dict with OPT_NON_STR_KEYS, if the object type is Unknown, add a fallback to use the python default str() function

https://github.com/ijl/orjson/issues/424#issuecomment-1710860721

This is a feature to allow unknown types (e.g. a custom implementation of an enum in my case, but could be anything) to be keys by just naively relying on the string representation. This is not elegant, and I agree with @ijl that "This is a sort of feature request if you squint", but the current behavior is to error so I think this is a marginal improvement on that. Happy to make any changes.

timkpaine avatar Jan 26 '24 20:01 timkpaine