You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Thanks to encoding hooks, why not supporting arbitrary objects as dict keys? #568
First, thanks for this great library!
I would like to serialize a dict whose keys are instances of a class coming from another library. I am already able to serialize these objects using enc_hook parameter to convert them as strings. But if these objects are converted to strings, why we cannot use them as keys for json dict ?
Thanks for opening this; you've found a bug! This currently works correctly for msgspec.msgpack.decode and msgspec.convert, but fails for msgspec.json.decode. Will fix.
Hi @jcrist, I got a chance to look at the fix and the corresponding tests. I copied your test below and made Custom inherit msgspec.Struct. Encoding still works but now decoding throws the following error
msgspec.ValidationError: Expected `object`, got `str` - at `key` in `$`
This is the code I used to generate the error (taken from your tests)
Activity
jcrist commentedon Nov 7, 2023
Thanks for opening this; you've found a bug! This currently works correctly for
msgspec.msgpack.decodeandmsgspec.convert, but fails formsgspec.json.decode. Will fix.user529481 commentedon Aug 14, 2024
Hi @jcrist, I got a chance to look at the fix and the corresponding tests. I copied your test below and made
Custominheritmsgspec.Struct. Encoding still works but now decoding throws the following errorThis is the code I used to generate the error (taken from your tests)
Is this expected behavior? Would it be difficult to support msgspec Structs as dictionary keys?