Skip to content

Conversation

@Str1kez
Copy link
Contributor

@Str1kez Str1kez commented Nov 29, 2025

When working with FastStream and the msgspec serializer, I encountered an issue where I couldn't retrieve custom types specified in the consumer's Struct from JSON.
Unfortunately, when manually publishing, it's impossible to specify how to make custom types serializable, since the encode method is static and doesn't take the MsgSpecSerializer state. However, there is a workaround: manually executing msgspec.json.encode with enc_hook when calling await broker.publish.

As far as I know, there's no easier way to cast types in msgspec.
https://jcristharif.com/msgspec/extending.html

@Lancetnik Lancetnik merged commit 334c1e2 into Lancetnik:main Nov 30, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants