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

Serde: Enable header modifications by custom serializer #509

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MDzaja
Copy link

@MDzaja MDzaja commented Jul 29, 2024

  • Breaking change? (if so, please describe the impact and migration path for existing application instances)

What changes did you make? (Give an overview)
Closes #346.
Extends io.kafbat.ui.serde.api.Serde.Serializer to support message headers editing by custom serializers.

Is there anything you'd like reviewers to focus on?

How Has This Been Tested? (put an "x" (case-sensitive!) next to an item)

  • No need to
  • Manually (please, describe, if necessary)
    A custom serializer was developed, and the feature was tested with it.
  • Unit checks
  • Integration checks
  • Covered by existing automation

Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. ENVIRONMENT VARIABLES)
  • My changes generate no new warnings (e.g. Sonar is happy)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

Check out Contributing and Code of Conduct

A picture of a cute animal (not mandatory but encouraged)
maki (4)

@MDzaja MDzaja requested a review from a team as a code owner July 29, 2024 20:56
@kapybro kapybro bot added status/triage Issues pending maintainers triage status/triage/manual Manual triage in progress status/triage/completed Automatic triage completed and removed status/triage Issues pending maintainers triage labels Jul 29, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hi MDzaja! 👋

Welcome, and thank you for opening your first PR in the repo!

Please wait for triaging by our maintainers.

Please take a look at our contributing guide.

@MDzaja MDzaja changed the title Feature/issue#346 Serde: Enable header modifications by custom serializer Jul 29, 2024
@Haarolean Haarolean requested review from iliax and germanosin August 10, 2024 15:07
@Haarolean Haarolean added type/enhancement En enhancement/improvement to an already existing feature scope/backend Related to backend changes area/serde Serialization & Deserialization (plugins) and removed status/triage/manual Manual triage in progress labels Sep 24, 2024
@Haarolean Haarolean added the hacktoberfest-accepted PRs accepted towards hacktoberfest goal and will be counted as approved label Oct 4, 2024
});
var serializer = serde.serializer(topic, type);
// Create a dynamic proxy instance for the Serde.Serializer interface
return (Serde.Serializer) Proxy.newProxyInstance(
Copy link
Member

Choose a reason for hiding this comment

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

why we'd need a proxy here?

Copy link
Author

Choose a reason for hiding this comment

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

We need a proxy here because the Serializer interface now has multiple methods, so we cannot use a simple lambda for wrapping (as was done previously). A proxy provides a generic, scalable, and clean solution to wrap all methods of the Serializer interface dynamically. This ensures that every method invocation on the interface is consistently wrapped with the necessary logic (e.g., wrapWithClassloader).

While it’s possible to use an explicit or anonymous class implementation to achieve the same goal, using a proxy reduces boilerplate and makes the code easier to maintain in the long run. For comparison, here’s how an anonymous wrapper class could look:

public Serde.Serializer serializer(String topic, Serde.Target type) {
    return wrapWithClassloader(() -> {
        var serializer = serde.serializer(topic, type);
        return new Serde.Serializer() {
            @Override
            public byte[] serialize(String input) {
                return wrapWithClassloader(() -> serializer.serialize(input));
            }

            @Override
            public byte[] serialize(String input, Headers headers) {
                return wrapWithClassloader(() -> serializer.serialize(input, headers));
            }
        };
    });
}

While this approach works, it introduces repetitive boilerplate for every method, which becomes harder to manage as the interface evolves.

Copy link

kapybro bot commented Dec 31, 2024

Further user feedback is requested. Please reply within 7 days or we might close the issue.

@kapybro kapybro bot assigned MDzaja Dec 31, 2024
Copy link

kapybro bot commented Jan 7, 2025

No feedback received within 7 days. Auto closing.

@kapybro kapybro bot closed this Jan 7, 2025
@Haarolean Haarolean reopened this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/serde Serialization & Deserialization (plugins) hacktoberfest-accepted PRs accepted towards hacktoberfest goal and will be counted as approved scope/backend Related to backend changes status/triage/completed Automatic triage completed type/enhancement En enhancement/improvement to an already existing feature
Projects
Status: Active
Development

Successfully merging this pull request may close these issues.

Serde: Enable header modifications by custom serializer
2 participants