Skip to content

Commit 8d23a1f

Browse files
committed
[ECO-5386] Removed jackson-msgpack dependencies
1. Implemented manual msgpack serialization 2. Updated tests
1 parent ef65124 commit 8d23a1f

File tree

13 files changed

+900
-246
lines changed

13 files changed

+900
-246
lines changed

gradle/libs.versions.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ mockk = "1.14.2"
2525
turbine = "1.2.0"
2626
ktor = "3.1.3"
2727
jetbrains-annoations = "26.0.2"
28-
jackson-msgpack = "0.8.11" # Compatible with msgpack-core 0.8.11
29-
jackson-param = "2.19.1" # Compatible with jackson-msgpack
3028

3129
[libraries]
3230
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
@@ -56,8 +54,6 @@ turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine
5654
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
5755
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
5856
jetbrains = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annoations" }
59-
jackson-msgpack = { group = "org.msgpack", name = "jackson-dataformat-msgpack", version.ref = "jackson-msgpack" }
60-
jackson-parameter-names = { group = "com.fasterxml.jackson.module", name = "jackson-module-parameter-names", version.ref = "jackson-param" }
6157

6258
[bundles]
6359
common = ["msgpack", "vcdiff-core"]

lib/src/main/java/io/ably/lib/objects/LiveObjectsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static LiveObjectsPlugin tryInitializeLiveObjectsPlugin(AblyRealtime ably
2727
public static LiveObjectSerializer getLiveObjectSerializer() {
2828
if (liveObjectSerializer == null) {
2929
try {
30-
Class<?> serializerClass = Class.forName("io.ably.lib.objects.DefaultLiveObjectSerializer");
30+
Class<?> serializerClass = Class.forName("io.ably.lib.objects.serialization.DefaultLiveObjectSerializer");
3131
liveObjectSerializer = (LiveObjectSerializer) serializerClass.getDeclaredConstructor().newInstance();
3232
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException |
3333
InvocationTargetException e) {

lib/src/main/java/io/ably/lib/types/ProtocolSerializer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ProtocolSerializer {
1414
/****************************************
1515
* Msgpack decode
1616
****************************************/
17-
17+
1818
public static ProtocolMessage readMsgpack(byte[] packed) throws AblyException {
1919
try {
2020
MessageUnpacker unpacker = Serialisation.msgpackUnpackerConfig.newUnpacker(packed);
@@ -27,30 +27,31 @@ public static ProtocolMessage readMsgpack(byte[] packed) throws AblyException {
2727
/****************************************
2828
* Msgpack encode
2929
****************************************/
30-
31-
public static byte[] writeMsgpack(ProtocolMessage message) {
30+
31+
public static byte[] writeMsgpack(ProtocolMessage message) throws AblyException {
3232
ByteArrayOutputStream out = new ByteArrayOutputStream();
3333
MessagePacker packer = Serialisation.msgpackPackerConfig.newPacker(out);
3434
try {
3535
message.writeMsgpack(packer);
36-
3736
packer.flush();
3837
return out.toByteArray();
39-
} catch(IOException e) { return null; }
38+
} catch (IOException ioe) {
39+
throw AblyException.fromThrowable(ioe);
40+
}
4041
}
4142

4243
/****************************************
4344
* JSON decode
4445
****************************************/
45-
46+
4647
public static ProtocolMessage fromJSON(String packed) throws AblyException {
4748
return Serialisation.gson.fromJson(packed, ProtocolMessage.class);
4849
}
4950

5051
/****************************************
5152
* JSON encode
5253
****************************************/
53-
54+
5455
public static byte[] writeJSON(ProtocolMessage message) throws AblyException {
5556
return Serialisation.gson.toJson(message).getBytes(Charset.forName("UTF-8"));
5657
}

live-objects/build.gradle.kts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ dependencies {
1313
implementation(project(":java"))
1414
implementation(libs.bundles.common)
1515
implementation(libs.coroutine.core)
16-
implementation(libs.jackson.msgpack)
17-
implementation(libs.jackson.parameter.names) // Add this
18-
1916

2017
testImplementation(kotlin("test"))
2118
testImplementation(libs.bundles.kotlin.tests)
@@ -47,12 +44,4 @@ tasks.register<Test>("runLiveObjectIntegrationTests") {
4744

4845
kotlin {
4946
explicitApi()
50-
51-
/**
52-
* Enables Jackson to map JSON property names to constructor parameters without use of @JsonProperty.
53-
* Adds metadata params to bytecode class. Approach is completely binary-compatible with consumers of the library.
54-
*/
55-
compilerOptions {
56-
javaParameters = true
57-
}
5847
}

live-objects/src/main/kotlin/io/ably/lib/objects/Helpers.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ internal enum class ProtocolMessageFormat(private val value: String) {
3939
override fun toString(): String = value
4040
}
4141

42-
internal class Binary(val data: ByteArray?) {
42+
internal class Binary(val data: ByteArray) {
4343
override fun equals(other: Any?): Boolean {
4444
if (this === other) return true
4545
if (other !is Binary) return false
46-
return data?.contentEquals(other.data) == true
46+
return data.contentEquals(other.data)
4747
}
4848

4949
override fun hashCode(): Int {
50-
return data?.contentHashCode() ?: 0
50+
return data.contentHashCode()
5151
}
5252
}
5353

5454
internal fun Binary.size(): Int {
55-
return data?.size ?: 0
55+
return data.size
5656
}

live-objects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package io.ably.lib.objects
33
import com.google.gson.JsonArray
44
import com.google.gson.JsonObject
55

6-
import com.fasterxml.jackson.annotation.JsonProperty
7-
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
8-
import com.fasterxml.jackson.databind.annotation.JsonSerialize
96
import com.google.gson.annotations.JsonAdapter
107
import com.google.gson.annotations.SerializedName
8+
import io.ably.lib.objects.serialization.InitialValueJsonSerializer
9+
import io.ably.lib.objects.serialization.ObjectDataJsonSerializer
10+
import io.ably.lib.objects.serialization.gson
1111

1212
/**
1313
* An enum class representing the different actions that can be performed on an object.
@@ -35,8 +35,6 @@ internal enum class MapSemantics(val code: Int) {
3535
* Spec: OD1
3636
*/
3737
@JsonAdapter(ObjectDataJsonSerializer::class)
38-
@JsonSerialize(using = ObjectDataMsgpackSerializer::class)
39-
@JsonDeserialize(using = ObjectDataMsgpackDeserializer::class)
4038
internal data class ObjectData(
4139
/**
4240
* A reference to another object, used to support composable object structures.
@@ -221,8 +219,6 @@ internal data class ObjectOperation(
221219
* Spec: OOP3h
222220
*/
223221
@JsonAdapter(InitialValueJsonSerializer::class)
224-
@JsonSerialize(using = InitialValueMsgpackSerializer::class)
225-
@JsonDeserialize(using = InitialValueMsgpackDeserializer::class)
226222
val initialValue: Binary? = null,
227223

228224
/** The initial value encoding defines how the initialValue should be interpreted.
@@ -319,7 +315,7 @@ internal data class ObjectMessage(
319315
* or validation of the @extras@ field itself, but should treat it opaquely, encoding it and passing it to realtime unaltered
320316
* Spec: OM2d
321317
*/
322-
val extras: Any? = null,
318+
val extras: JsonObject? = null,
323319

324320
/**
325321
* Describes an operation to be applied to an object.
@@ -336,7 +332,6 @@ internal data class ObjectMessage(
336332
* Spec: OM2g
337333
*/
338334
@SerializedName("object")
339-
@JsonProperty("object")
340335
val objectState: ObjectState? = null,
341336

342337
/**

live-objects/src/main/kotlin/io/ably/lib/objects/Serialization.kt

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)