orjson
orjson copied to clipboard
Default to str() for Unknown objects as keys when using `OPT_NON_STR_KEYS`
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.