-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
}); | ||
var serializer = serde.serializer(topic, type); | ||
// Create a dynamic proxy instance for the Serde.Serializer interface | ||
return (Serde.Serializer) Proxy.newProxyInstance( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Further user feedback is requested. Please reply within 7 days or we might close the issue. |
No feedback received within 7 days. Auto closing. |
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)
A custom serializer was developed, and the feature was tested with it.
Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)
Check out Contributing and Code of Conduct
A picture of a cute animal (not mandatory but encouraged)