-
-
Notifications
You must be signed in to change notification settings - Fork 118
How to serialize (JSON) a type reference? #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What json output are you expecting? |
I want to make the de-serialization as generic as possible for various attrs classes (their instances are sent as JSON messages via MQTT). For this purpose, the respective type information should be contained in the message (in a container). Since this information is needed by cattrs.structure. |
Do you only want the class name in the JSON payload, or more information? |
To rebuild a type object one needs the class name ( At the moment I store these two values. I'm sure this could be done via hooks, which I haven't looked into yet. But maybe a general json-lib support for type-object would be the better. |
Interesting, ok. We're working on what we're calling tagged union support, this sounds like it. It's un/structuring a union with some metadata attached so it can be recreated on the other end. Looks like you want the metadata to be a fully-qualified name for a class, and the structuring hook to import it. I'll keep this use case in mind. |
Yes, this is what I want. |
(I know it's not a cattrs issue.)
I'm looking for a way to JSON-serialize a type-ref inside a attrs-class.
But type-refs aren't supported by json-lib.
See a litte example:
Are there any ideas on how to achieve my goal?
The text was updated successfully, but these errors were encountered: