Skip to content

Commit

Permalink
Various simple code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
danischroeter committed Jul 5, 2023
1 parent ffa5648 commit 3e290c1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ To use this serializer, you need to do two things:

We provide several versions of the library:

Version | Kryo Compatibility | Available Scala Versions | Tested with |
--------|--------------------|--------------------------|-----------------------------------------------------------------|
v1.0.x | Kryo-5.4 | 2.12,2.13,3.1 | JDK: OpenJdk11,OpenJdk17 Scala: 2.12.18,2.13.11,3.3.0 |
| Version | Kryo Compatibility | Available Scala Versions | Tested with |
|---------|--------------------|--------------------------|-----------------------------------------------------------------|
| v1.0.x | Kryo-5.4 | 2.12,2.13,3.1 | JDK: OpenJdk11,OpenJdk17 Scala: 2.12.18,2.13.11,3.3.0 |


Note that we use semantic versioning - see [semver.org](https://semver.org/).
Expand All @@ -65,7 +65,7 @@ To use the official release of scala-kryo-serialization in Maven projects, pleas
</snapshots>
<id>central</id>
<name>Maven Central Repository</name>
<url>http://repo1.maven.org/maven2</url>
<url>https://repo1.maven.org/maven2</url>
</repository>

<dependency>
Expand Down Expand Up @@ -107,7 +107,7 @@ You may need to repeat the process several times until you see no further log
messages about implicitly registered classes.

Another useful trick is to provide your own custom initializer for Kryo (see
below) and inside it you registerclasses of a few objects that are typically
below) and inside it, you registerclasses of a few objects that are typically
used by your application, for example:

```scala
Expand Down Expand Up @@ -275,8 +275,8 @@ like `immutable.ListMap` -- the resolver will choose the more-specific one when

`SubclassResolver` should be used with care -- even when it is turned on, you should define and
register most of your classes explicitly, as usual. But it is a helpful way to tame the complexity
of some class hierarchies, when that complexity can be treated as an implementation detail and all
of the subclasses can be serialized and deserialized identically.
of some class hierarchies, when that complexity can be treated as an implementation detail and all
the subclasses can be serialized and deserialized identically.


Using serializers with different configurations
Expand Down Expand Up @@ -315,17 +315,17 @@ Using Kryo on JDK 17
Kryo needs modules to be opened for reflection when serializing basic JDK classes.
Those options have to be passed to the JVM, for example in sbt:
```sbt
javaOptions ++= Seq("--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", "--add-opens", "java.base/java.math=ALL-UNNAMED"),
javaOptions ++= Seq("--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", "--add-opens", "java.base/java.math=ALL-UNNAMED")
```

To use unsafe transformations, the following access must be granted:
```sbt
javaOptions ++= Seq("--add-opens", "java.base/java.nio=ALL-UNNAMED", "--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED"),
javaOptions ++= Seq("--add-opens", "java.base/java.nio=ALL-UNNAMED", "--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED")
```

How do I build this library on my own?
--------------------------------------
If you wish to build the library on your own, you need to check out the project from Github and do
If you wish to build the library on your own, you need to check out the project from GitHub and do
```
sbt compile publishM2
```
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lazy val root: Project = project.in(file("."))
.settings(publish / skip := true)
.aggregate(core)

lazy val core: Project = Project("core", file("core"))
lazy val core: Project = project.in(file("core"))
.settings(moduleSettings)
.settings(description := "pekko-serialization implementation using kryo - core implementation")
.settings(name := "scala-kryo-serialization")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private[kryo] class KryoSerializerBackend(val kryo: Kryo, val bufferSize: Int, v
if (useManifest) {
val clazz = manifest.flatMap(ReflectionHelper.getClassFor(_, classLoader).toOption)
clazz match {
case Some(c) => kryo.readObject(buffer, c).asInstanceOf[AnyRef]
case Some(c) => kryo.readObject(buffer, c)
case _ => throw new RuntimeException("Object of unknown class cannot be deserialized")
}
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.altoo.serialization.kryo.scala.serializer

import com.esotericsoftware.kryo.util.{DefaultClassResolver, ListReferenceResolver}
import io.altoo.serialization.kryo.scala.ScalaVersionSerializers
import io.altoo.serialization.kryo.scala.serializer.{ScalaEnumNameSerializer, ScalaKryo}
import io.altoo.serialization.kryo.scala.testkit.{AbstractKryoTest, KryoSerializationTesting}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.scalatest.matchers.should.Matchers
import java.nio.ByteBuffer
import scala.collection.{immutable, mutable}
import scala.collection.immutable.{HashMap, TreeMap}
import scala.collection.mutable.AnyRefMap

object TransformationserializerTest {
private val defaultConfig =
Expand Down Expand Up @@ -99,22 +98,22 @@ abstract class TransformationserializerTest(name: String, testConfig: String) ex

it should "serialize and deserialize mutable AnyRefMap[String,Any] successfully" in {
val r = new scala.util.Random(0L)
val tm = AnyRefMap[String, Any](
val tm = mutable.AnyRefMap[String, Any](
"foo" -> r.nextDouble(),
"bar" -> "foo,bar,baz",
"baz" -> 124L,
"hash" -> HashMap[Int, Int](r.nextInt() -> r.nextInt(), 5 -> 500, 10 -> r.nextInt()))

val serialized = serializer.serialize(tm).get
val deserialized = serializer.deserialize[AnyRefMap[String, Any]](serialized)
val deserialized = serializer.deserialize[mutable.AnyRefMap[String, Any]](serialized)
deserialized shouldBe util.Success(tm)

val bb = ByteBuffer.allocate(serialized.length * 2)

serializer.serialize(tm, bb) shouldBe a[util.Success[?]]
bb.flip()

val bufferDeserialized = serializer.deserialize[AnyRefMap[String, Any]](bb)
val bufferDeserialized = serializer.deserialize[mutable.AnyRefMap[String, Any]](bb)
bufferDeserialized shouldBe util.Success(tm)
}

Expand Down

0 comments on commit 3e290c1

Please sign in to comment.