implementing JSON Serialization of Custom Classes in Python 3.8 Using Marshmallow
I've looked through the documentation and I'm still confused about I'm migrating some code and I'm having trouble serializing a custom class to JSON using Marshmallow in Python 3.8... I have a class called `User` that contains attributes like `id`, `name`, and `email`. I created a schema for it, but when I try to serialize an instance of `User`, I get a `TypeError: Object of type User is not JSON serializable`. Hereβs the relevant code snippet: ```python from marshmallow import Schema, fields, post_dump class User: def __init__(self, id, name, email): self.id = id self.name = name self.email = email class UserSchema(Schema): id = fields.Int() name = fields.Str() email = fields.Str() @post_dump def add_custom_field(self, data, **kwargs): data['full_name'] = f"{data['name']} <{data['email']}>" return data user = User(1, 'Alice', 'alice@example.com') schema = UserSchema() result = schema.dump(user) print(result) ``` The `UserSchema` seems to be set up correctly, but I need to figure out why I'm getting this behavior during the serialization process. I've tried converting the `User` instance to a dictionary using `vars(user)` before dumping it with Marshmallow, but that didn't resolve the scenario. I also checked the Marshmallow documentation, but didnβt find a specific mention of custom class serialization. Any insights on how to resolve this would be greatly appreciated! This is part of a larger service I'm building. Am I missing something obvious? What am I doing wrong? This issue appeared after updating to Python 3.8 3.11.