diff --git a/services-bytebuf-codec/src/main/java/io/scalecube/services/transport/api/DefaultHeadersCodec.java b/services-api/src/main/java/io/scalecube/services/transport/api/JdkCodec.java
similarity index 70%
rename from services-bytebuf-codec/src/main/java/io/scalecube/services/transport/api/DefaultHeadersCodec.java
rename to services-api/src/main/java/io/scalecube/services/transport/api/JdkCodec.java
index c7782d338..9d574a646 100644
--- a/services-bytebuf-codec/src/main/java/io/scalecube/services/transport/api/DefaultHeadersCodec.java
+++ b/services-api/src/main/java/io/scalecube/services/transport/api/JdkCodec.java
@@ -4,14 +4,17 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.OutputStream;
+import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-/** Simple binary codec for headers service message. */
-public final class DefaultHeadersCodec implements HeadersCodec {
+/** Simple headers and data codec based on JDK only. */
+public class JdkCodec implements DataCodec, HeadersCodec {
/**
* {@inheritDoc}
@@ -21,6 +24,19 @@ public String contentType() {
return "application/octet-stream";
}
+ /**
+ * Uses Jdk Object Serialization.
+ *
+ *
{@inheritDoc}
+ */
+ @Override
+ public void encode(OutputStream stream, Object value) throws IOException {
+ try (ObjectOutputStream oos = new ObjectOutputStream(stream)) {
+ oos.writeObject(value);
+ oos.flush();
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -40,6 +56,20 @@ public void encode(OutputStream stream, Map headers) throws IOEx
}
}
+ /**
+ * Uses Jdk Object Serialization.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Object decode(InputStream stream, Type type) throws IOException {
+ try (ObjectInputStream is = new ObjectInputStream(stream)) {
+ return is.readObject();
+ } catch (ClassNotFoundException e) {
+ throw new IOException(e.getMessage(), e);
+ }
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/services-api/src/main/resources/META-INF/services/io.scalecube.services.transport.api.DataCodec b/services-api/src/main/resources/META-INF/services/io.scalecube.services.transport.api.DataCodec
new file mode 100644
index 000000000..a8885001a
--- /dev/null
+++ b/services-api/src/main/resources/META-INF/services/io.scalecube.services.transport.api.DataCodec
@@ -0,0 +1 @@
+io.scalecube.services.transport.api.JdkCodec
\ No newline at end of file
diff --git a/services-api/src/test/java/io/scalecube/services/transport/api/JdkCodecTest.java b/services-api/src/test/java/io/scalecube/services/transport/api/JdkCodecTest.java
new file mode 100644
index 000000000..cf4307ace
--- /dev/null
+++ b/services-api/src/test/java/io/scalecube/services/transport/api/JdkCodecTest.java
@@ -0,0 +1,70 @@
+package io.scalecube.services.transport.api;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.stream.Stream;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class JdkCodecTest {
+
+ private final DataCodec codec = new JdkCodec();
+
+ @ParameterizedTest
+ @MethodSource("provider")
+ void test(Object body) throws IOException {
+ Object decoded = writeAndRead(body);
+ assertEquals(body, decoded);
+ }
+
+ static Stream