close
Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import scala.util.matching.Regex
import com.twitter.chill.java.PackageRegistrar
import _root_.java.io.Serializable

import scala.collection.JavaConverters._

/** This class has a no-arg constructor, suitable for use with reflection instantiation
* It has no registered serializers, just the standard Kryo configured for Kryo.
*/
Expand Down Expand Up @@ -87,6 +89,19 @@ class ScalaKryoInstantiator extends EmptyScalaKryoInstantiator {

class ScalaCollectionsRegistrar extends IKryoRegistrar {
def apply(newK: Kryo) {
// for binary compat this is here, but could be moved to RichKryo
def useField[T](cls: Class[T]) {
val fs = new com.esotericsoftware.kryo.serializers.FieldSerializer(newK, cls)
fs.setIgnoreSyntheticFields(false) // scala generates a lot of these attributes
newK.register(cls, fs)
}
// The wrappers are private classes:
useField(List(1, 2, 3).asJava.getClass)
useField(List(1, 2, 3).iterator.asJava.getClass)
useField(Map(1 -> 2, 4 -> 3).asJava.getClass)
useField(new _root_.java.util.ArrayList().asScala.getClass)
useField(new _root_.java.util.HashMap().asScala.getClass)

/*
* Note that subclass-based use: addDefaultSerializers, else: register
* You should go from MOST specific, to least to specific when using
Expand Down
6 changes: 6 additions & 0 deletions chill-scala/src/test/scala/com/twitter/chill/KryoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import scala.collection.mutable.{ArrayBuffer => MArrayBuffer, HashMap => MHashMa
import _root_.java.util.PriorityQueue
import _root_.java.util.Locale
import scala.collection.mutable
import scala.collection.JavaConverters._

/*
* This is just a test case for Kryo to deal with. It should
* be outside KryoSpec, otherwise the enclosing class, KryoSpec
Expand Down Expand Up @@ -82,6 +84,10 @@ class KryoSpec extends Specification with BaseProperties {
Vector(1,2,3,4,5),
TestValMap(null),
Some("junk"),
List(1, 2, 3).asJava,
Map("hey" -> 1, "you" -> 2).asJava,
new _root_.java.util.ArrayList(Seq(1, 2, 3).asJava).asScala,
new _root_.java.util.HashMap[Int,Int](Map(1 -> 2, 3 -> 4).asJava).asScala,
(),
'hai)
.asInstanceOf[List[AnyRef]]
Expand Down