Menu

Custom Class Serialization in Workflow SDK - Vercel
📰
0

Custom Class Serialization in Workflow SDK - Vercel

Vercel News·Nathan Rajlich·4 days ago
#WFn7z7Om
Reading 0:00
15s threshold

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 ) :…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More