Skip to content

Commit a4fae86

Browse files
committed
Switched to anonymous class
1 parent ce901bd commit a4fae86

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

api/src/main/java/io/kafbat/ui/serdes/SerdeInstance.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import io.kafbat.ui.serde.api.SchemaDescription;
44
import io.kafbat.ui.serde.api.Serde;
55
import java.io.Closeable;
6-
import java.lang.reflect.InvocationTargetException;
76
import java.util.Optional;
87
import java.util.function.Supplier;
98
import java.util.regex.Pattern;
109
import javax.annotation.Nullable;
1110
import lombok.Getter;
1211
import lombok.RequiredArgsConstructor;
1312
import lombok.extern.slf4j.Slf4j;
14-
import org.springframework.cglib.proxy.Proxy;
13+
import org.apache.kafka.common.header.Headers;
1514

1615
@Slf4j
1716
@RequiredArgsConstructor
@@ -80,20 +79,20 @@ public boolean canDeserialize(String topic, Serde.Target type) {
8079
}
8180

8281
public Serde.Serializer serializer(String topic, Serde.Target type) {
83-
var serializer = serde.serializer(topic, type);
84-
// Create a dynamic proxy instance for the Serde.Serializer interface
85-
return (Serde.Serializer) Proxy.newProxyInstance(
86-
classLoader,
87-
new Class<?>[] { Serde.Serializer.class },
88-
(proxy, method, args) -> wrapWithClassloader(() -> { // Invocation handler to wrap method calls
89-
try {
90-
// Invoke the actual serializer method with the provided arguments
91-
return method.invoke(serializer, args);
92-
} catch (IllegalAccessException | InvocationTargetException e) {
93-
throw new RuntimeException("Error invoking serializer method", e.getCause());
94-
}
95-
})
96-
);
82+
return wrapWithClassloader(() -> {
83+
var serializer = serde.serializer(topic, type);
84+
return new Serde.Serializer() {
85+
@Override
86+
public byte[] serialize(String input) {
87+
return wrapWithClassloader(() -> serializer.serialize(input));
88+
}
89+
90+
@Override
91+
public byte[] serialize(String input, Headers headers) {
92+
return wrapWithClassloader(() -> serializer.serialize(input, headers));
93+
}
94+
};
95+
});
9796
}
9897

9998
public Serde.Deserializer deserializer(String topic, Serde.Target type) {

serde-api/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ tasks.register('javadocJar', Jar) {
1515
from javadoc.destinationDir
1616
}
1717

18+
dependencies {
19+
implementation libs.kafka.clients
20+
}
21+
1822
artifacts {
1923
archives sourceJar, javadocJar
2024
}

0 commit comments

Comments
 (0)