Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit d7e34f7

Browse files
author
mpv1989
committed
Add support for scala.math.BigInt and scala.math.BigDecimal
1 parent 0dd3553 commit d7e34f7

File tree

4 files changed

+66
-41
lines changed

4 files changed

+66
-41
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Added support for:
1212
* scala.Option
1313
* scala.collection.immutable.List
1414
* scala.collection.immutable.Map
15+
* scala.math.BigInt
16+
* scala.math.BigDecimal
1517

1618

1719
## Maven
@@ -23,7 +25,7 @@ To add the dependency to your project with maven, add the following code to your
2325
<dependency>
2426
<groupId>com.arangodb</groupId>
2527
<artifactId>velocypack-module-scala</artifactId>
26-
<version>1.0.0</version>
28+
<version>1.0.2</version>
2729
</dependency>
2830
</dependencies>
2931
```

src/main/scala/com/arangodb/velocypack/module/scala/VPackScalaModule.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ class VPackScalaModule extends VPackModule {
1212
context.registerDeserializer(classOf[Option[Any]], VPackScalaDeserializers.OPTION, true)
1313
context.registerDeserializer(classOf[List[Any]], VPackScalaDeserializers.LIST)
1414
context.registerDeserializer(classOf[Map[Any, Any]], VPackScalaDeserializers.MAP)
15+
context.registerDeserializer(classOf[BigInt], VPackScalaDeserializers.BIG_INT)
16+
context.registerDeserializer(classOf[BigDecimal], VPackScalaDeserializers.BIG_DECIMAL)
1517

1618
context.registerSerializer(classOf[Option[Any]], VPackScalaSerializers.OPTION)
1719
context.registerSerializer(classOf[List[Any]], VPackScalaSerializers.LIST)
1820
context.registerSerializer(classOf[Map[Any, Any]], VPackScalaSerializers.MAP)
1921
context.registerEnclosingSerializer(classOf[Map[Any, Any]], VPackScalaSerializers.MAP)
22+
context.registerSerializer(classOf[BigInt], VPackScalaSerializers.BIG_INT)
23+
context.registerSerializer(classOf[BigDecimal], VPackScalaSerializers.BIG_DECIMAL)
2024
}
2125

2226
}
Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
1-
package com.arangodb.velocypack.module.scala.internal
2-
3-
import com.arangodb.velocypack.VPackDeserializer
4-
import com.arangodb.velocypack.VPackDeserializationContext
5-
import com.arangodb.velocypack.VPackSlice
6-
import com.arangodb.velocypack.VPackDeserializerParameterizedType
7-
import java.lang.reflect.ParameterizedType
8-
import scala.collection.JavaConversions._
9-
import scala.collection.JavaConverters._
10-
11-
object VPackScalaDeserializers {
12-
13-
val OPTION = new VPackDeserializerParameterizedType[Option[Any]] {
14-
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): Option[Any] =
15-
throw new UnsupportedOperationException
16-
17-
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext, t: ParameterizedType): Option[Any] = {
18-
val value = context.deserialize(vpack, t.getActualTypeArguments()(0).asInstanceOf[Class[Any]])
19-
value match {
20-
case null => None
21-
case _ => Some(value)
22-
}
23-
}
24-
}
25-
26-
val LIST = new VPackDeserializerParameterizedType[List[Any]] {
27-
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): List[Any] =
28-
throw new UnsupportedOperationException
29-
30-
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext, t: ParameterizedType): List[Any] = {
31-
val clazz = t.getActualTypeArguments()(0).asInstanceOf[Class[Any]]
32-
vpack.arrayIterator().map { slice => context.deserialize(slice, clazz) }.toList
33-
}
34-
}
35-
36-
val MAP = new VPackDeserializer[Map[Any, Any]] {
37-
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): Map[Any, Any] =
38-
context.deserialize(vpack, classOf[java.util.Map[Any, Any]]).toMap
39-
}
40-
1+
package com.arangodb.velocypack.module.scala.internal
2+
3+
import com.arangodb.velocypack.VPackDeserializer
4+
import com.arangodb.velocypack.VPackDeserializationContext
5+
import com.arangodb.velocypack.VPackSlice
6+
import com.arangodb.velocypack.VPackDeserializerParameterizedType
7+
import java.lang.reflect.ParameterizedType
8+
import scala.collection.JavaConversions._
9+
import scala.collection.JavaConverters._
10+
11+
object VPackScalaDeserializers {
12+
13+
val OPTION = new VPackDeserializerParameterizedType[Option[Any]] {
14+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): Option[Any] =
15+
throw new UnsupportedOperationException
16+
17+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext, t: ParameterizedType): Option[Any] = {
18+
val value = context.deserialize(vpack, t.getActualTypeArguments()(0).asInstanceOf[Class[Any]])
19+
value match {
20+
case null => None
21+
case _ => Some(value)
22+
}
23+
}
24+
}
25+
26+
val LIST = new VPackDeserializerParameterizedType[List[Any]] {
27+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): List[Any] =
28+
throw new UnsupportedOperationException
29+
30+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext, t: ParameterizedType): List[Any] = {
31+
val clazz = t.getActualTypeArguments()(0).asInstanceOf[Class[Any]]
32+
vpack.arrayIterator().map { slice => context.deserialize(slice, clazz) }.toList
33+
}
34+
}
35+
36+
val MAP = new VPackDeserializer[Map[Any, Any]] {
37+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): Map[Any, Any] =
38+
context.deserialize(vpack, classOf[java.util.Map[Any, Any]]).toMap
39+
}
40+
41+
val BIG_INT = new VPackDeserializer[BigInt] {
42+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): BigInt =
43+
BigInt.javaBigInteger2bigInt(context.deserialize(vpack, classOf[java.math.BigInteger]))
44+
}
45+
46+
val BIG_DECIMAL = new VPackDeserializer[BigDecimal] {
47+
def deserialize(parent: VPackSlice, vpack: VPackSlice, context: VPackDeserializationContext): BigDecimal =
48+
BigDecimal.javaBigDecimal2bigDecimal(context.deserialize(vpack, classOf[java.math.BigDecimal]))
49+
}
50+
4151
}

src/main/scala/com/arangodb/velocypack/module/scala/internal/VPackScalaSerializers.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,13 @@ object VPackScalaSerializers {
2525
context.serialize(builder, attribute, mapAsJavaMap(value))
2626
}
2727

28+
val BIG_INT = new VPackSerializer[BigInt] {
29+
def serialize(builder: VPackBuilder, attribute: String, value: BigInt, context: VPackSerializationContext): Unit =
30+
context.serialize(builder, attribute, value.bigInteger)
31+
}
32+
33+
val BIG_DECIMAL = new VPackSerializer[BigDecimal] {
34+
def serialize(builder: VPackBuilder, attribute: String, value: BigDecimal, context: VPackSerializationContext): Unit =
35+
context.serialize(builder, attribute, value.bigDecimal)
36+
}
2837
}

0 commit comments

Comments
 (0)