pickling icon indicating copy to clipboard operation
pickling copied to clipboard

Pickling fails with a weird issue

Open opensorceror opened this issue 5 years ago • 0 comments

I'm trying to serialize an object to JSON using scala-pickling 0.10.1 and Scala 2.11, but am having a very strange issue. I've replicated a minimal example below:

import org.apache.hadoop.io.compress.CompressionCodecFactory
import scala.pickling.Defaults._
import scala.pickling.json._
    
trait foo {
  var compressionCodecFactory1: CompressionCodecFactory = _
  val compressionCodecFactory2: CompressionCodecFactory = null
}
    
class blah extends foo
 
object FooFoo {
  def main(args: Array[String]) = {
        
  val k = new blah
  val pkl = k.pickle // compilation fails with error "Cannot generate a pickler for blah"
  }
}

However, if I remove or comment out var compressionCodecFactory1: CompressionCodecFactory = _ within the trait foo, it compiles and pickles perfectly. I've also tried adding the @transient notation to this var, but it fails with the same error.

Why could this possibly be happening?

opensorceror avatar Sep 01 '18 23:09 opensorceror