我尝试使用JBoss Serialization
存储我的对象,这是我的帮助:
object JBoss {
def toBytes(exe: Any) = {
val baos = new ByteArrayOutputStream
val oos = new JBossObjectOutputStream(baos)
(oos writeObject exe, oos flush, oos close, baos close)
baos.toByteArray
}
// Object in byte form
type ByteObj = Array[Byte]
def to[T](exe: ByteObj) = {
val bais = new ByteArrayInputStream(exe)
val ois = new JBossObjectInputStream(bais)
val rs = ois.readObject.asInstanceOf[T]
ois.close
rs
}
}
当我尝试使用它时:
try {
class A(val x: String, s: String) { override def toString = s"A(x = $x, s = $s)" }
val bytes = JBoss.toBytes(new A("one", "two"))
} catch {
case e: Throwable => println(e)
}
我收到以下异常:java.lang.NoClassDefFoundError: gnu/trove/TObjectHashingStrategy
如何解决此问题?