0

I need to save/serialize three data structures [viz., one DenseVector, one DenseMatrix and one double] at the same time and subsequently retrieve those. Probably I need to create a class in Scala with these three members, create an object and finally serialize the object. Is there any other/better way to do the same in Scala?

Thanks and regards,

learning_spark
  • 669
  • 1
  • 8
  • 19

2 Answers2

0

If you don't need to worry about binary compatibility (it doesn't need to be stored for a long time, etc.) It's probably safe to just use a Tuple3 and then use Java's built in serialization facilities. That's assuming you don't need it to be as small as possible...

dlwh
  • 2,257
  • 11
  • 23
0

The easiest way to do so is by creating those classes as case class,Case classes are serializable by default . you can see nice article of marshaling /unmarshaling using jackson here

or using liftweb:

import net.liftweb.json._
  import Extraction._

implicit val formats = DefaultFormats

case class Foo(String name)
val foo = Foo("John")
val json:JValue = decompose(foo) 

unmarshal
val fooFromJson:Foo = json.extract[Foo]
println(fooFromJson.name) //result John
igx
  • 4,101
  • 11
  • 43
  • 88