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:
import { WORKFLOW_SERIALIZE , WORKFLOW_DESERIALIZE } from "@workflow/serde" ;
interface SerializedSandbox {
metadata : SandboxSnapshot ;
routes : SandboxRouteData [ ] ;
}
export class Sandbox {
sandbox : SandboxSnapshot ;
routes : SandboxRouteData [ ] ;
// Serialize a Sandbox instance to plain data
static [ WORKFLOW_SERIALIZE ] ( instance : Sandbox ) :…