Support for Custom Serialization in Queues (e.g. `superjson`)
Hi everyone,
I’d like to propose or ask about native support for custom serialization and deserialization logic when working with Cloudflare Queues.
In our current use case, we deal with objects that include Date instances and other complex structures. We’d like to use SuperJSON (or a similar tool) as our default serializer because it handles these cases much more gracefully than JSON.stringify.
The problem is that, at the moment, we have to manually call
superjson.stringify
every time we push data to the queue, and then manually parse it again with superjson.parse
when we pull messages. This results in repetitive code scattered throughout the application, especially when iterating over messages during batch processing.
Moreover, when we manually use SuperJSON.stringify, the result is stored in the queue as a string — not as a structured JSON object.
Feature request / question: Would it be possible to allow registration of a global (or per-queue) custom serialize() / deserialize() function pair? These would be automatically applied on enqueue/dequeue operations.
This would significantly reduce boilerplate and improve developer ergonomics.
Thanks for considering this! Curious if others have encountered similar pain points or found better workarounds.2 Replies
Just curious, why not just pass in the object directly?
Queues doesn’t stringify objects for transmission/storage
?Crossposting also
Please do not post your question in multiple channels/post it multiple times per the rules at #😃welcome-and-rules. It creates confusion for people trying to help you and doesn't get your issue or question solved any faster.