Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Combination of separate compilation, generated case class picklers, and custom pickler leads to empty serialization #139

Open
@mmirold

Description

@mmirold

Dear all,

Disclaimer: I am new to scala-pickling, so I am probably just doing something wrong.

I have two source folders A and B. Folder A contains the following scala code:

import scala.pickling._
import scala.pickling.json._
import java.util.UUID

class UUIDPickler(implicit val format: PickleFormat) extends SPickler[UUID] with Unpickler[UUID] {

  def pickle(picklee: UUID, builder: PBuilder) {
    builder.beginEntry(picklee)
    builder.putField("uuid", b => b.hintStaticallyElidedType().hintTag(FastTypeTag.ScalaString).beginEntry(picklee.toString()).endEntry())
    builder.endEntry()
  }

  def unpickle(tag: => FastTypeTag[_], reader: PReader): UUID = {
    reader.beginEntry()
    val uuidString = reader.readField("uuid").unpickle[String]
    reader.endEntry()
    UUID.fromString(uuidString)
  }
}

object UUIDPickler {
  implicit def customUUIDPickler(implicit format: PickleFormat) = new UUIDPickler
}

trait Super {
  val a: Int
  val b: String
}

case class Concrete(a: Int, b: String, c: UUID) extends Super

object Main extends App {
  val s1 = Concrete(19, "Hallo", UUID.randomUUID())
  Bla.doIt(s1)
}

object Bla {
  def doIt(obj: Super): Unit = {
    import UUIDPickler._
    val objpickle = obj.pickle
    println(objpickle.value)
  }
}

If I compile folder A using

scalac -cp ~/.m2/repository/org/scala-lang/scala-pickling_2.11/0.8.0/scala-pickling_2.11-0.8.0.jar:/Users/mmirold/pickltest/A *.scala

I get the expected result:

❯❯❯ scala -cp ./:/Users/mmirold/.m2/repository/org/scala-lang/scala-pickling_2.11/0.8.0/scala-pickling_2.11-0.8.0.jar:/Users/mmirold/pickltest/A Main                                                                                                                 

{
  "tpe": "Concrete",
  "a": 19,
  "b": "Hallo",
  "c": {
    "uuid": "52eb5ddb-240a-47d9-a32b-6eda2648b55a"
  }
}

However, if I compile the following code in folder B:

import java.util.UUID

case class ConcreteB(a: Int, b: String, c: UUID) extends Super

object Main extends App {

  Bla.doIt(ConcreteB(1,"hallo", UUID.randomUUID))

}

via

scalac -cp ~/.m2/repository/org/scala-lang/scala-pickling_2.11/0.8.0/scala-pickling_2.11-0.8.0.jar:/Users/mmirold/pickltest/A *.scala

and execute it, I get

❯❯❯ scala -cp ./:/Users/mmirold/.m2/repository/org/scala-lang/scala-pickling_2.11/0.8.0/scala-pickling_2.11-0.8.0.jar:/Users/mmirold/pickltest/A Main
{
  "tpe": "ConcreteB",
  "a": 1,
  "b": "hallo",
  "c": {

  }
}

The result is the same for scala-pickling 0.8.0 and 0.9.0. Am I doing something stupid? Is this intended behavior?

Thanks & best regards,
Michael

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions