This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 0673c7b8 feat(kotlin): Introduce kotlin package with stdlib 
collections and tests (#1877)
0673c7b8 is described below

commit 0673c7b82ed5cf522d7c5b18551a8fd73efacaa1
Author: Yi Wen Wong <[email protected]>
AuthorDate: Mon Oct 14 08:20:51 2024 -0700

    feat(kotlin): Introduce kotlin package with stdlib collections and tests 
(#1877)
    
    
    
    ## What does this PR do?
    
    This PR adds a base project for Kotlin on the JVM.
    - It adds a pom.xml based on the java project.
    - Adds a Serializer class that registers base collection classes not
    covered by the JVM.
    - Adds code to test all documented collections in the kotlin stdlib via
    TestNG.
    - Adds register and adds serializers for EmptyList, EmptySet, EmptyMap
    classes.
    - This PR does not handle kotlin `withDefault` wrapper classes, as that
    requires serializing arbitrary lambdas.
    
    ## Related issues
    
    - #683
    
    ## Does this PR introduce any user-facing change?
    
    This PR creates a new fury-kotlin JAR, no documentation yet from the
    main project.
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    N/A
    
    ---------
    
    Co-authored-by: Shawn Yang <[email protected]>
---
 kotlin/README.md                                   |  21 +++
 kotlin/pom.xml                                     | 182 ++++++++++++++++++
 .../fury/serializer/kotlin/KotlinSerializers.java  |  56 ++++++
 .../fury/serializer/kotlin/CollectionBuilder.kt    |  50 +++++
 .../fury/serializer/kotlin/CollectionSerializer.kt |  83 +++++++++
 .../fury/serializer/kotlin/KotlinToJavaClass.kt    |  27 +++
 .../serializer/kotlin/CollectionSerializerTest.kt  | 207 +++++++++++++++++++++
 7 files changed, 626 insertions(+)

diff --git a/kotlin/README.md b/kotlin/README.md
new file mode 100644
index 00000000..255b2ed6
--- /dev/null
+++ b/kotlin/README.md
@@ -0,0 +1,21 @@
+# Apache Fury™ Kotlin
+
+This provides additional Fury support for Kotlin Serialization on JVM:
+
+Most standard kotlin types are already supported out of the box with the 
default Fury java implementation.
+
+Fury Kotlin provides additional tests and implementation support for Kotlin 
types.
+
+Fury Kotlin is tested and works with the following types:
+
+- stdlib `collection`: `ArrayDeque`, `ArrayList`, `HashMap`,`HashSet`, 
`LinkedHashSet`, `LinkedHashMap`.
+- `ArrayList`, `HashMap`,`HashSet`, `LinkedHashSet`, `LinkedHashMap` works out 
of the box with the default java implementation.
+
+Additional support is added for the following classes in kotlin:
+
+- Empty collections: `emptyList`, `emptyMap`, `emptySet`
+- Collections: `ArrayDeque`
+
+Additional Notes:
+
+- wrappers classes created from `withDefault` method is currently not 
supported.
diff --git a/kotlin/pom.xml b/kotlin/pom.xml
new file mode 100644
index 00000000..24bccb95
--- /dev/null
+++ b/kotlin/pom.xml
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+    <groupId>org.apache.fury</groupId>
+    <artifactId>fury-kotlin</artifactId>
+    <version>0.9.0-SNAPSHOT</version>
+    <modelVersion>4.0.0</modelVersion>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <kotlin.code.style>official</kotlin.code.style>
+        <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
+    </properties>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-compiler-plugin</artifactId>
+                    <version>3.10.1</version>
+                    <executions>
+                        <execution>
+                            <id>default-compile</id>
+                            <phase>none</phase>
+                        </execution>
+                        <execution>
+                            <id>default-testCompile</id>
+                            <phase>none</phase>
+                        </execution>
+                        <execution>
+                            <id>java-compile</id>
+                            <phase>compile</phase>
+                            <goals>
+                                <goal>compile</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-source-plugin</artifactId>
+                    <version>3.0.1</version>
+                    <executions>
+                        <execution>
+                            <id>attach-sources</id>
+                            <goals>
+                                <goal>jar</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-javadoc-plugin</artifactId>
+                    <version>3.1.0</version>
+                    <executions>
+                        <execution>
+                            <id>attach-javadocs</id>
+                            <goals>
+                                <goal>jar</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                    <configuration>
+                        <doclint>none</doclint>
+                        <bottom>
+                            Copyright © 2023-2024, The Apache Software 
Foundation. Apache Fury™, Fury™, and Apache
+                            are either registered trademarks or trademarks of 
the Apache Software Foundation.
+                        </bottom>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-shade-plugin</artifactId>
+                    <version>3.2.1</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-deploy-plugin</artifactId>
+                    <version>2.7</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-gpg-plugin</artifactId>
+                    <version>1.6</version>
+                    <executions>
+                        <execution>
+                            <id>sign-artifacts</id>
+                            <goals>
+                                <goal>sign</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+        <plugins>
+            <plugin>
+                <groupId>org.jetbrains.kotlin</groupId>
+                <artifactId>kotlin-maven-plugin</artifactId>
+                <version>2.0.20</version>
+                <executions>
+                    <execution>
+                        <id>compile</id>
+                        <phase>process-sources</phase>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                        <configuration>
+                            <sourceDirs>
+                                
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
+                                
<sourceDir>${project.basedir}/src/main/java</sourceDir>
+                            </sourceDirs>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>test-compile</id>
+                        <phase>test-compile</phase>
+                        <goals>
+                            <goal>test-compile</goal>
+                        </goals>
+                        <configuration>
+                            <sourceDirs>
+                                
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
+                            </sourceDirs>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.22.2</version>
+            </plugin>
+            <plugin>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>2.22.2</version>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.fury</groupId>
+            <artifactId>fury-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-test-testng</artifactId>
+            <version>2.0.20</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib</artifactId>
+            <version>2.0.20</version>
+        </dependency>
+    </dependencies>
+</project>
diff --git 
a/kotlin/src/main/java/org/apache/fury/serializer/kotlin/KotlinSerializers.java 
b/kotlin/src/main/java/org/apache/fury/serializer/kotlin/KotlinSerializers.java
new file mode 100644
index 00000000..14a368fb
--- /dev/null
+++ 
b/kotlin/src/main/java/org/apache/fury/serializer/kotlin/KotlinSerializers.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fury.serializer.kotlin;
+
+import org.apache.fury.Fury;
+import org.apache.fury.resolver.ClassResolver;
+import org.apache.fury.serializer.collection.CollectionSerializers;
+import org.apache.fury.serializer.collection.MapSerializers;
+
+
+/**
+ * KotlinSerializers provide default serializers for kotlin.
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class KotlinSerializers {
+    public static void registerSerializers(Fury fury) {
+        ClassResolver resolver = fury.getClassResolver();
+
+        // EmptyList
+        Class emptyListClass = KotlinToJavaClass.INSTANCE.getEmptyListClass();
+        resolver.register(emptyListClass);
+        resolver.registerSerializer(emptyListClass, new 
CollectionSerializers.EmptyListSerializer(fury, emptyListClass));
+
+        // EmptySet
+        Class emptySetClass = KotlinToJavaClass.INSTANCE.getEmptySetClass();
+        resolver.register(emptySetClass);
+        resolver.registerSerializer(emptySetClass, new 
CollectionSerializers.EmptySetSerializer(fury, emptySetClass));
+
+        // EmptyMap
+        Class emptyMapClass = KotlinToJavaClass.INSTANCE.getEmptyMapClass();
+        resolver.register(emptyMapClass);
+        resolver.registerSerializer(emptyMapClass, new 
MapSerializers.EmptyMapSerializer(fury, emptyMapClass));
+
+        // Non-Java collection implementation in kotlin stdlib.
+        Class arrayDequeClass = 
KotlinToJavaClass.INSTANCE.getArrayDequeClass();
+        resolver.register(arrayDequeClass);
+        resolver.registerSerializer(arrayDequeClass, new 
KotlinArrayDequeSerializer(fury, arrayDequeClass));
+    }
+}
diff --git 
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/CollectionBuilder.kt 
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/CollectionBuilder.kt
new file mode 100644
index 00000000..24593287
--- /dev/null
+++ 
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/CollectionBuilder.kt
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fury.serializer.kotlin
+
+/**
+ * Collection builder interface adapts an iterable to allow incremental build 
by the fury protocol.
+ */
+interface CollectionBuilder <E, T: Iterable<E>> {
+    fun add(element: E): Boolean
+    fun result(): T
+}
+
+/**
+ * Abstract builder for [kotlin.collections.List] interface.
+ */
+abstract class AbstractListBuilder<E, T:List<E>>
+    : CollectionBuilder<E, T>, AdaptedCollection<E>() {
+    protected open val builder: MutableList<E> = mutableListOf()
+    override val size: Int
+        get() = builder.size
+    override fun add(element: E) =
+        builder.add(element)
+    override fun iterator(): MutableIterator<E> = builder.iterator()
+}
+
+/**
+ * Builder for [kotlin.collections.ArrayDeque].
+ */
+class ArrayDequeBuilder<E>(
+    override val builder: ArrayDeque<E>
+): AbstractListBuilder<E, ArrayDeque<E>>() {
+    override fun result(): ArrayDeque<E> = builder
+}
diff --git 
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/CollectionSerializer.kt
 
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/CollectionSerializer.kt
new file mode 100644
index 00000000..36bf6c37
--- /dev/null
+++ 
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/CollectionSerializer.kt
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.memory.MemoryBuffer
+import org.apache.fury.serializer.collection.AbstractCollectionSerializer
+
+/**
+ * Serializer for kotlin collections.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class AbstractKotlinCollectionSerializer<E, T: Iterable<E>>(
+    fury: Fury,
+    cls: Class<T>
+) : AbstractCollectionSerializer<T>(fury, cls) {
+    abstract override fun onCollectionWrite(buffer: MemoryBuffer, value: T): 
Collection<E>
+
+    override fun read(buffer: MemoryBuffer): T {
+        val collection = newCollection(buffer)
+        val numElements = getAndClearNumElements()
+        if (numElements != 0) readElements(fury, buffer, collection, 
numElements)
+        return onCollectionRead(collection)
+    }
+
+    override fun onCollectionRead(collection: Collection<*>): T {
+        val builder = collection as CollectionBuilder<E, T>
+        return builder.result()
+    }
+}
+
+/**
+ * Serializer for [[kotlin.collections.ArrayDeque]].
+ */
+class KotlinArrayDequeSerializer<E> (
+    fury: Fury,
+    cls: Class<ArrayDeque<E>>,
+) : AbstractKotlinCollectionSerializer<E, ArrayDeque<E>>(fury, cls) {
+    override fun onCollectionWrite(buffer: MemoryBuffer, value: 
ArrayDeque<E>): Collection<E> {
+        val adapter = IterableAdapter<E>(value)
+        buffer.writeVarUint32Small7(adapter.size)
+        return adapter
+    }
+    override fun newCollection(buffer: MemoryBuffer): Collection<E> {
+        val numElements = buffer.readVarUint32()
+        setNumElements(numElements)
+        return ArrayDequeBuilder<E>(ArrayDeque<E>(numElements))
+    }
+}
+
+typealias AdaptedCollection<E> = java.util.AbstractCollection<E>
+
+/**
+ * An adapter which wraps a kotlin iterable into a [[java.util.Collection]].
+ */
+private class IterableAdapter<E>(
+    coll: Iterable<E>
+) : AdaptedCollection<E>() {
+    private val mutableList = coll.toMutableList()
+
+    override val size: Int
+        get() = mutableList.count()
+
+    override fun iterator(): MutableIterator<E> =
+        mutableList.iterator()
+}
diff --git 
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/KotlinToJavaClass.kt 
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/KotlinToJavaClass.kt
new file mode 100644
index 00000000..824a2ebf
--- /dev/null
+++ 
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/KotlinToJavaClass.kt
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fury.serializer.kotlin
+
+object KotlinToJavaClass {
+    val ArrayDequeClass = ArrayDeque::class.java
+    val EmptyListClass = emptyList<Any>().javaClass
+    val EmptySetClass = emptySet<Any>().javaClass
+    val EmptyMapClass = emptyMap<Any, Any>().javaClass
+}
diff --git 
a/kotlin/src/test/kotlin/org/apache/fury/serializer/kotlin/CollectionSerializerTest.kt
 
b/kotlin/src/test/kotlin/org/apache/fury/serializer/kotlin/CollectionSerializerTest.kt
new file mode 100644
index 00000000..c43f4410
--- /dev/null
+++ 
b/kotlin/src/test/kotlin/org/apache/fury/serializer/kotlin/CollectionSerializerTest.kt
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fury.serializer.kotlin
+
+import org.apache.fury.Fury
+import org.apache.fury.config.Language
+import org.testng.Assert.assertEquals
+import org.testng.annotations.Test
+
+class CollectionSerializerTest {
+    @Test
+    fun testSerializeArrayDeque() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val arrayDeque = ArrayDeque(listOf(1, 2, 3, 4, 5))
+        assertEquals(arrayDeque, fury.deserialize(fury.serialize(arrayDeque)))
+    }
+
+    @Test
+    fun testSerializeArrayList() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+
+        KotlinSerializers.registerSerializers(fury)
+        val arrayList = arrayListOf(1, 2, 3, 4, 5)
+        assertEquals(arrayList, fury.deserialize(fury.serialize(arrayList)))
+    }
+
+    @Test
+    fun testSerializeEmptyList() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val emptyList = listOf<Int>()
+        assertEquals(emptyList, fury.deserialize(fury.serialize(emptyList)))
+    }
+
+    @Test
+    fun testSerializeList() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val list = listOf(1, 2, 3, 4, 5)
+        assertEquals(list, fury.deserialize(fury.serialize(list)))
+    }
+
+    @Test
+    fun testSerializeMutableList() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val mutableList = mutableListOf(1, 2, 3, 4, 5)
+        assertEquals(mutableList, 
fury.deserialize(fury.serialize(mutableList)))
+    }
+
+    @Test
+    fun testSerializeEmptySet() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val emptySet = setOf<Int>()
+        assertEquals(emptySet, fury.deserialize(fury.serialize(emptySet)))
+    }
+
+    @Test
+    fun testSerializeSet() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val set = setOf(1, 2, 3, 4, 5)
+        assertEquals(set, fury.deserialize(fury.serialize(set)))
+    }
+
+    @Test
+    fun testSerializeMutableSet() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val mutableSet = mutableSetOf(1, 2, 3, 4, 5)
+        assertEquals(mutableSet, fury.deserialize(fury.serialize(mutableSet)))
+    }
+
+    @Test
+    fun testSerializeHashSet() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val set = hashSetOf(1, 2, 3, 4, 5)
+        assertEquals(set, fury.deserialize(fury.serialize(set)))
+    }
+
+    @Test
+    fun testSerializeLinkedSet() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val set = linkedSetOf(1, 2, 3, 4, 5)
+        assertEquals(set, fury.deserialize(fury.serialize(set)))
+    }
+
+    @Test
+    fun testSerializeEmptyMap() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val emptyMap: Map<Int, String> = mapOf()
+        assertEquals(emptyMap, fury.deserialize(fury.serialize(emptyMap)))
+    }
+
+    @Test
+    fun testSerializeMap() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val map = mapOf(1 to "one", 2 to "two", 3 to "three")
+        assertEquals(map, fury.deserialize(fury.serialize(map)))
+    }
+
+    @Test
+    fun testSerializeMutableMap() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val mutableMap = mapOf(1 to "one", 2 to "two", 3 to "three")
+        assertEquals(mutableMap, fury.deserialize(fury.serialize(mutableMap)))
+    }
+
+    @Test
+    fun testSerializeHashMap() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val map = hashMapOf(1 to "one", 2 to "two", 3 to "three")
+        assertEquals(map, fury.deserialize(fury.serialize(map)))
+    }
+
+    @Test
+    fun testSerializeLinkedMap() {
+        val fury: Fury = Fury.builder()
+            .withLanguage(Language.JAVA)
+            .requireClassRegistration(true)
+            .build()
+        KotlinSerializers.registerSerializers(fury)
+
+        val map = linkedMapOf(1 to "one", 2 to "two", 3 to "three")
+        assertEquals(map, fury.deserialize(fury.serialize(map)))
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to