scala / pickling

Fast, customizable, boilerplate-free pickling support for Scala
lampwww.epfl.ch/~hmiller/pickling
BSD 3-Clause "New" or "Revised" License
831 stars 79 forks source link

Pickling fails with a weird issue #455

Open opensorceror opened 6 years ago

opensorceror commented 6 years ago

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?