序列化

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

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错误

你可能感兴趣的:(序列化)