Custom Class Serialization in Workflow SDK
Workflow SDK now supports custom class serialization, letting you pass your own class instances between workflow and step functions.
Workflow SDK serializes standard JavaScript types like primitives, objects, arrays, Date, Map, Set, and more. Custom class instances were previously not supported because the serialization system didn't know how to reconstruct them. With the new @workflow/serde package, you can define how your classes are serialized and deserialized by implementing two static methods using WORKFLOW_SERIALIZE and WORKFLOW_DESERIALIZE.
Here's an example of how we used custom serialization in @vercel/sandbox to greatly improve DX:
Once implemented, instances of your class can be passed as arguments and return values between workflow and step functions, with the serialization system handling conversion automatically.
- See the full example application utilizing
@vercel/sandboxand Workflow SDK. - Read the serialization documentation to learn more.