@@ -43,6 +43,8 @@ import scala.util.matching.Regex
43
43
import com .twitter .chill .java .PackageRegistrar
44
44
import _root_ .java .io .Serializable
45
45
46
+ import scala .collection .JavaConverters ._
47
+
46
48
/** This class has a no-arg constructor, suitable for use with reflection instantiation
47
49
* It has no registered serializers, just the standard Kryo configured for Kryo.
48
50
*/
@@ -87,6 +89,19 @@ class ScalaKryoInstantiator extends EmptyScalaKryoInstantiator {
87
89
88
90
class ScalaCollectionsRegistrar extends IKryoRegistrar {
89
91
def apply (newK : Kryo ) {
92
+ // for binary compat this is here, but could be moved to RichKryo
93
+ def useField [T ](cls : Class [T ]) {
94
+ val fs = new com.esotericsoftware.kryo.serializers.FieldSerializer (newK, cls)
95
+ fs.setIgnoreSyntheticFields(false ) // scala generates a lot of these attributes
96
+ newK.register(cls, fs)
97
+ }
98
+ // The wrappers are private classes:
99
+ useField(List (1 , 2 , 3 ).asJava.getClass)
100
+ useField(List (1 , 2 , 3 ).iterator.asJava.getClass)
101
+ useField(Map (1 -> 2 , 4 -> 3 ).asJava.getClass)
102
+ useField(new _root_.java.util.ArrayList ().asScala.getClass)
103
+ useField(new _root_.java.util.HashMap ().asScala.getClass)
104
+
90
105
/*
91
106
* Note that subclass-based use: addDefaultSerializers, else: register
92
107
* You should go from MOST specific, to least to specific when using
0 commit comments