Handling case classes in twitter chill (Scala interface to Kryo)?
Asked Answered
B

1

8

Twitter-chill looks like a good solution to the problem of how to serialize efficiently in Scala without excessive boilerplate.

However, I don't see any evidence of how they handle case classes. Does this just work automatically or does something need to be done (e.g. creating a zero-arg constructor)?

I have some experience with the WireFormat serialization mechanism built into Scoobi, which is a Scala Hadoop wrapper similar to Scalding. They have serializers for case classes up to 22 arguments that use the apply and unapply methods and do type matching on the arguments to these functions to retrieve the types. (This might not be necessary in Kryo/chill.)

Bryna answered 31/12, 2013 at 1:57 Comment(0)
C
4

They generally just work (as long as the component members are also serializable by Kryo):

case class Foo(id: Int, name: String)

// setup
val instantiator = new ScalaKryoInstantiator
instantiator.setRegistrationRequired(false)
val kryo = instantiator.newKryo()

// write
val data = Foo(1,"bob")
val buffer = new Array[Byte](4096]
val output = new Output(buffer)
kryo.writeObject(output, data)

// read
val input = new Input(buffer)
val data2 = kryo.readObject(input,classOf[Foo]).asInstanceOf[Foo]
Chang answered 17/4, 2015 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.