Skip to content

Deserialize in Common lib - #4

Closed
RossStewart wants to merge 3 commits into
mainfrom
jsonSerialization
Closed

RossStewart wants to merge 3 commits into
mainfrom
jsonSerialization

Conversation

@RossStewart

Copy link
Copy Markdown

No description provided.

@RossStewart
RossStewart requested a review from a team May 18, 2026 13:55

@lewisrenfrew lewisrenfrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better than the extensions approach from before, but we are still forcing consuming code to handle 'raw' messages and then remember to construct a JsonMessage from the raw message to access the new Body property, which is sort of just as much boilerplate as doing the deserialization themselves or calling the previous extension method.

After reminding myself how the publishing side works, I reckon a better approach is one that is symmetrical to that one - on that side I wrote a JsonMessagePublisher that wraps the raw RabbitPublisher, and so hides serialization from the caller entirely.

We could do the same on the consuming side with an abstract JsonMessageHandler of T that implements IMessageHandler, handles deserialization internally, and exposes a strongly-typed HandleAsync method for subclasses to override. That way the consuming service never touches raw messages or worries about deserialization at all - we can just call the JsonMessageHandler's HandleAsync which keeps things nice and clean.

@RossStewart

Copy link
Copy Markdown
Author

This is better than the extensions approach from before, but we are still forcing consuming code to handle 'raw' messages and then remember to construct a JsonMessage from the raw message to access the new Body property, which is sort of just as much boilerplate as doing the deserialization themselves or calling the previous extension method.

After reminding myself how the publishing side works, I reckon a better approach is one that is symmetrical to that one - on that side I wrote a JsonMessagePublisher that wraps the raw RabbitPublisher, and so hides serialization from the caller entirely.

We could do the same on the consuming side with an abstract JsonMessageHandler of T that implements IMessageHandler, handles deserialization internally, and exposes a strongly-typed HandleAsync method for subclasses to override. That way the consuming service never touches raw messages or worries about deserialization at all - we can just call the JsonMessageHandler's HandleAsync which keeps things nice and clean.

Agree with all this. Gave me a few things to think about. Just put another version of it up there trying to adhere to this comment. Just making a local copy so I can test it with the print service. Let me know any thoughts

@lewisrenfrew

Copy link
Copy Markdown
Contributor

This is better than the extensions approach from before, but we are still forcing consuming code to handle 'raw' messages and then remember to construct a JsonMessage from the raw message to access the new Body property, which is sort of just as much boilerplate as doing the deserialization themselves or calling the previous extension method.
After reminding myself how the publishing side works, I reckon a better approach is one that is symmetrical to that one - on that side I wrote a JsonMessagePublisher that wraps the raw RabbitPublisher, and so hides serialization from the caller entirely.
We could do the same on the consuming side with an abstract JsonMessageHandler of T that implements IMessageHandler, handles deserialization internally, and exposes a strongly-typed HandleAsync method for subclasses to override. That way the consuming service never touches raw messages or worries about deserialization at all - we can just call the JsonMessageHandler's HandleAsync which keeps things nice and clean.

Agree with all this. Gave me a few things to think about. Just put another version of it up there trying to adhere to this comment. Just making a local copy so I can test it with the print service. Let me know any thoughts

I already had to throw one together just to see if it would actually work:

#5

I like it

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