Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SystemTextJsonSerializer.SupportsFastPath method #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

flobernd
Copy link
Member

@flobernd flobernd commented Jan 31, 2025

The DefaultRequestResponseSerializer implementation in the Elasticsearch client (based on SystemTextJsonSerializer) overrides the Deserialize/Serialize methods to drive special serialization, if the type implements IStreamSerializable. This is done to support e.g. NDJSON request/response bodies.

Fast-path (de-)serialization currently incorrectly bypasses this special handling.

This PR provides a way to selectively disable the fast-path (de-)serialization for specific types.

@flobernd flobernd added enhancement New feature or request v0.5.8 labels Jan 31, 2025
/// </para>
/// <para>
/// In some cases, when the concrete <see cref="SystemTextJsonSerializer"/> based serializer implementation overrides one or more of
/// the named methods, the default fast-path behavior might be undesired. The <see cref="SupportsFastPath"/> method can be used to
Copy link
Member

Choose a reason for hiding this comment

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

Can you expand why the fast path might be undesirable?

I grasp the use case for not prefering the fast path.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the user overrides one of these methods, there is probably a reason for doing so.

Like mentioned, fast path will bypass the Deserialize/Serialize method invocation, which in conclusion will as well bypass execution of the user code (which is why fast path is undesirable in these cases, otherwise there wouldn't have been a good reason for overriding Deserialize/Serialize in the first place).

Is that unclear from the doc comment?

Copy link
Member

Choose a reason for hiding this comment

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

Comments make more sense in the morning then late at night :)

Copy link
Member Author

Choose a reason for hiding this comment

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

True :D Thanks for the review! I will try to rephrase it a bit before merging to make it more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v0.5.8
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants