Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.arangodb</groupId>
<artifactId>velocypack-module-scala_2.12</artifactId>
<artifactId>velocypack-module-scala_2.13</artifactId>
<version>1.2.0</version>
<inceptionYear>2017</inceptionYear>
<packaging>jar</packaging>
Expand Down Expand Up @@ -80,7 +80,7 @@
<artifactId>sbt-compiler-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<scalaVersion>2.12.12</scalaVersion>
<scalaVersion>2.13.1</scalaVersion>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -185,7 +185,7 @@
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.12</artifactId>
<artifactId>scalatest_2.13</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -209,8 +209,8 @@
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.12</artifactId>
<version>3.0.0</version>
<artifactId>scalatest_2.13</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ class VPackScalaModule extends VPackModule {
classOf[List[Any]],
classOf[Vector[Any]],
classOf[Seq[Any]],
Seq(Unit).getClass,
Seq(()).getClass,
Seq.empty.getClass,
Nil.getClass
).foreach(context.registerSerializer(_, VPackScalaSerializers.SEQ))

Set(
classOf[HashMap.HashMap1[_, _]],
classOf[HashMap.HashTrieMap[_, _]],
classOf[Map.Map1[_, _]],
classOf[Map.Map2[_, _]],
classOf[Map.Map3[_, _]],
classOf[Map.Map4[_, _]],
classOf[HashMap[_, _]],
classOf[TreeMap[_, _]],
ListMap(Unit -> Unit).getClass,
ListMap(() -> ()).getClass,
classOf[Map[_, _]]
).foreach(context.registerSerializer(_, VPackScalaSerializers.MAP))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.arangodb.velocypack.VPackDeserializationContext
import com.arangodb.velocypack.VPackSlice
import com.arangodb.velocypack.VPackDeserializerParameterizedType
import java.lang.reflect.ParameterizedType
import scala.collection.JavaConversions._
import scala.jdk.CollectionConverters._

object VPackScalaDeserializers {

Expand All @@ -28,7 +28,7 @@ object VPackScalaDeserializers {

def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext, t: ParameterizedType): List[Any] = {
val clazz = t.getActualTypeArguments()(0).asInstanceOf[Class[Any]]
vpack.arrayIterator().map { slice: VPackSlice => context.deserialize[Any](slice, clazz) }.toList
vpack.arrayIterator().asScala.map { slice: VPackSlice => context.deserialize[Any](slice, clazz) }.toList
}
}

Expand All @@ -38,13 +38,13 @@ object VPackScalaDeserializers {

def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext, t: ParameterizedType): Vector[Any] = {
val clazz = t.getActualTypeArguments()(0).asInstanceOf[Class[Any]]
vpack.arrayIterator().map { slice: VPackSlice => context.deserialize[Any](slice, clazz) }.toVector
vpack.arrayIterator().asScala.map { slice: VPackSlice => context.deserialize[Any](slice, clazz) }.toVector
}
}

val MAP = new VPackDeserializer[Map[Any, Any]] {
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): Map[Any, Any] =
context.deserialize[java.util.Map[Any, Any]](vpack, classOf[java.util.Map[Any, Any]]).toMap
context.deserialize[java.util.Map[Any, Any]](vpack, classOf[java.util.Map[Any, Any]]).asScala.toMap
}

val BIG_INT = new VPackDeserializer[BigInt] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.arangodb.velocypack.VPackSerializer
import com.arangodb.velocypack.VPackSerializationContext
import com.arangodb.velocypack.VPackBuilder
import scala.collection.mutable.ListBuffer
import scala.collection.JavaConversions._
import scala.jdk.CollectionConverters._

object VPackScalaSerializers {

Expand All @@ -15,14 +15,14 @@ object VPackScalaSerializers {

val SEQ = new VPackSerializer[Seq[Any]] {
def serialize(builder: VPackBuilder, attribute: String, value: Seq[Any], context: VPackSerializationContext): Unit = {
val list: _root_.java.util.List[Any] = ListBuffer(value: _*)
val list: _root_.java.util.List[Any] = ListBuffer(value: _*).asJava
context.serialize(builder, attribute, list)
}
}

val MAP = new VPackSerializer[Map[Any, Any]] {
def serialize(builder: VPackBuilder, attribute: String, value: Map[Any, Any], context: VPackSerializationContext): Unit =
context.serialize(builder, attribute, mapAsJavaMap(value))
context.serialize(builder, attribute, value.asJava)
}

val BIG_INT = new VPackSerializer[BigInt] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.arangodb.velocypack.module.scala

import org.scalatest.Matchers
import org.scalatest.FunSuite
import org.scalatest.funsuite._
import org.scalatest.matchers._
import scala.beans.BeanProperty
import com.arangodb.velocypack.VPack
import com.arangodb.velocypack.VPackBuilder
Expand All @@ -11,7 +11,7 @@ case class ListTestEntity(@BeanProperty var s: List[String] = List(), @BeanPrope
def this() = this(s = List())
}

class VPackListTest extends FunSuite with Matchers {
class VPackListTest extends AnyFunSuite with should.Matchers {

test("serialize list") {
val vp = new VPack.Builder().registerModule(new VPackScalaModule).build()
Expand All @@ -33,15 +33,15 @@ class VPackListTest extends FunSuite with Matchers {

test("deserialize list") {
val builder = new VPackBuilder()
builder add ValueType.OBJECT
builder add ("s", ValueType.ARRAY)
builder add "hello world"
builder.add(ValueType.OBJECT)
builder.add("s", ValueType.ARRAY)
builder.add("hello world")
builder.close
builder add ("i", ValueType.ARRAY)
builder add new Integer(69)
builder.add ("i", ValueType.ARRAY)
builder.add(Integer.valueOf(69))
builder.close
builder add ("o", ValueType.ARRAY)
builder add ValueType.OBJECT
builder.add ("o", ValueType.ARRAY)
builder.add(ValueType.OBJECT)
builder.close
builder.close
builder.close
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.arangodb.velocypack.module.scala

import com.arangodb.velocypack.module.scala.VPackMapTest._
import com.arangodb.velocypack.{VPack, VPackBuilder, ValueType}
import org.scalatest.{FunSuite, Matchers}
import org.scalatest.funsuite._
import org.scalatest.matchers._

import scala.beans.BeanProperty
import scala.collection.immutable._
Expand All @@ -11,7 +11,7 @@ case class MapTestEntity(@BeanProperty var m: Map[String, Any] = Map()) {
def this() = this(Map())
}

class VPackMapTest extends FunSuite with Matchers {
class VPackMapTest extends AnyFunSuite with should.Matchers {

test("serialize map") {
val vp = new VPack.Builder().registerModule(new VPackScalaModule).build()
Expand Down Expand Up @@ -52,22 +52,28 @@ class VPackMapTest extends FunSuite with Matchers {
val vp = new VPack.Builder().registerModule(new VPackScalaModule).build()

val entity = MapTestEntity(m =
HashTrieMap("seq" -> Seq(
HashTrieMap("foo" -> 42),
SortedMap("foo" -> 42),
ListMap("foo" -> 42),
HashMap("foo" -> 42),
Map("foo" -> 42),
ListMap.empty,
Map.empty
)))
HashMap( // scala <= 2.12 -> HashTrieMap is in fact used behind the scene when Map size is >= 5
"seq" -> Seq(
HashMap("foo" -> 42), // scala <= 2.12 -> Map.Map1, Map.Map2, Map.Map3, HashMap4 is in fact used behind the scene when Map size is <5
SortedMap("foo" -> 42),
ListMap("foo" -> 42),
HashMap("foo" -> 42),
Map("foo" -> 42),
ListMap.empty,
Map.empty
),
"seq2" -> Seq(Map("foo" -> 42)), // Map.Map1
"seq3" -> Seq(Map("foo" -> 42, "foo2" -> 42)), // Map.Map2
"seq4" -> Seq(Map("foo" -> 42, "foo2" -> 42, "foo3" -> 42)), // Map.Map3
"seq5" -> Seq(Map("foo" -> 42, "foo2" -> 42, "foo3" -> 42, "foo4" -> 42)), // Map.Map4
))

val vpack = vp.serialize(entity)
vpack should not be null
vpack.isObject should be(true)
vpack.size should be(1)
vpack.get("m").isObject should be(true)
vpack.get("m").size should be(1)
vpack.get("m").size should be(5)
vpack.get("m").get("seq").isArray should be(true)

vpack.get("m").get("seq").get(0).isObject should be(true)
Expand Down Expand Up @@ -100,14 +106,35 @@ class VPackMapTest extends FunSuite with Matchers {

vpack.get("m").get("seq").get(5).isObject should be(true)
vpack.get("m").get("seq").get(5).size should be(0)

vpack.get("m").get("seq2").get(0).isObject should be(true)
vpack.get("m").get("seq2").get(0).size should be(1)
vpack.get("m").get("seq2").get(0).get("foo").isInt should be(true)
vpack.get("m").get("seq2").get(0).get("foo").getAsInt should be(42)

vpack.get("m").get("seq3").get(0).isObject should be(true)
vpack.get("m").get("seq3").get(0).size should be(2)
vpack.get("m").get("seq3").get(0).get("foo2").isInt should be(true)
vpack.get("m").get("seq3").get(0).get("foo2").getAsInt should be(42)

vpack.get("m").get("seq4").get(0).isObject should be(true)
vpack.get("m").get("seq4").get(0).size should be(3)
vpack.get("m").get("seq4").get(0).get("foo3").isInt should be(true)
vpack.get("m").get("seq4").get(0).get("foo3").getAsInt should be(42)

vpack.get("m").get("seq5").get(0).isObject should be(true)
vpack.get("m").get("seq5").get(0).size should be(4)
vpack.get("m").get("seq5").get(0).get("foo4").isInt should be(true)
vpack.get("m").get("seq5").get(0).get("foo4").getAsInt should be(42)

}

test("deserialize map") {
val builder = new VPackBuilder
builder add ValueType.OBJECT
builder add ("m", ValueType.OBJECT)
builder add ("s", "hello world")
builder add ("i", new Integer(69))
builder.add(ValueType.OBJECT)
builder.add("m", ValueType.OBJECT)
builder.add("s", "hello world")
builder.add("i", Integer.valueOf(69))
builder.close
builder.close

Expand All @@ -119,11 +146,3 @@ class VPackMapTest extends FunSuite with Matchers {
entity.m.get("i") should be(Some(69))
}
}

object VPackMapTest {

object HashTrieMap {
def apply[A, B](pairs: (A, B)*): Map[A, B] = new HashMap.HashTrieMap(0, Array(HashMap(pairs: _*)), pairs.size)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package com.arangodb.velocypack.module.scala

import scala.beans.BeanProperty

import org.scalatest.Finders
import org.scalatest.FunSuite
import org.scalatest.Matchers
import org.scalatest.funsuite._
import org.scalatest.matchers._

import com.arangodb.velocypack.VPack
import com.arangodb.velocypack.VPackBuilder
Expand All @@ -16,7 +15,7 @@ case class OptionTestEntity(@BeanProperty var s: Option[String] = Option.empty,
def this() = this(s = Option.empty)
}

class VPackOptionTest extends FunSuite with Matchers {
class VPackOptionTest extends AnyFunSuite with should.Matchers {

test("serialize Option") {
val vp = new VPack.Builder().registerModule(new VPackScalaModule).build()
Expand Down Expand Up @@ -51,11 +50,11 @@ class VPackOptionTest extends FunSuite with Matchers {

test("deserialize null") {
val builder = new VPackBuilder()
builder add ValueType.OBJECT
builder add ("s", ValueType.NULL)
builder add ("i", ValueType.NULL)
builder add ("o", ValueType.NULL)
builder close
builder.add(ValueType.OBJECT)
builder.add("s", ValueType.NULL)
builder.add("i", ValueType.NULL)
builder.add("o", ValueType.NULL)
builder.close

val vp = new VPack.Builder().registerModule(new VPackScalaModule).build()
val entity: OptionTestEntity = vp.deserialize(builder.slice, classOf[OptionTestEntity])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.arangodb.velocypack.module.scala
import java.{util => ju}

import com.arangodb.velocypack.{VPack, VPackBuilder, ValueType}
import org.scalatest.{FunSuite, Matchers}
import org.scalatest.funsuite._
import org.scalatest.matchers._


import scala.beans.BeanProperty

Expand All @@ -15,7 +17,7 @@ case class WrappedSeqTestEntity(map: Map[String, Any], seq: Seq[Any], opt: Optio
def this() = this(Map.empty, Nil, None)
}

class VPackSeqTest extends FunSuite with Matchers {
class VPackSeqTest extends AnyFunSuite with should.Matchers {

test("serialize seq") {
val vp = new VPack.Builder().registerModule(new VPackScalaModule).build()
Expand Down