[英]com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): scala.Tuple2
I can't go through the simplest example of serialization using Kryo on scala. 我无法讲解在Scala上使用Kryo进行序列化的最简单示例。 Do i need to register a specific serializer for this? 我需要为此注册一个特定的序列化器吗? thanks 谢谢
val kryo = new Kryo()
kryo.setRegistrationRequired(false)
kryo.register(classOf[scala.Tuple2[Any, Any]])
val intstringtuple = (100, "somestring")
val outStream = new ByteArrayOutputStream()
val output = new Output(outStream)
kryo.writeClassAndObject(output, obj)
output.flush()
val input = new com.esotericsoftware.kryo.io.Input(new ByteArrayInputStream(outStream.toByteArray))
val obj1 = kryo.readClassAndObject(input)
添加如下内容可以解决该问题:
kryo.register(classOf[scala.Tuple2[Any, Any]], new com.twitter.chill.Tuple2Serializer)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.