序列化

2019-03-29  本文已影响0人  Kinvo

父类序列化不了可以改成组合的方式,把原来的父类当成一个成员,代码如下:

class SOAPAScalaLogger() extends Serializable {
  @transient
  var logger: SOAPALogger = null
  var moduleName: String = null

  def setModuleName(name: String): Unit = {
    moduleName = name
  }

  private def writeObject(out: ObjectOutputStream): Unit = {
    out.defaultWriteObject()
    out.writeObject(SOAPALogger.getAppID())
  }

  private def readObject(in: ObjectInputStream): Unit = {
    in.defaultReadObject()
    val appID = in.readObject().asInstanceOf[String]
    SOAPALogger.setAppID(appID)
    logger = SOAPALogManager.getLogger(moduleName, new SOAPACategoryFactory).asInstanceOf[SOAPALogger];
  }
}

java的序列化
scala的序列化
java的zipfile序列化
no valid constructor错误

上一篇下一篇

猜你喜欢

热点阅读