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

pickling a java.lang.Byte doesn't contain value (unpickles to zero) #263

Open
windelknecht opened this issue Jan 8, 2015 · 3 comments
Open

Comments

@windelknecht
Copy link

Using:

"org.scala-lang" %% "scala-pickling" % "0.9.1"

When:

import scala.pickling._, json._
val r1: java.lang.Byte = 13.toByte
val r2 = r1.pickle

Then:

{
    "tpe": "java.lang.Byte"
}

But scala.Byte works:

val z1: Byte = 13.toByte
val z2 = z1.pickle
{
    "tpe": "scala.Byte",
    "value": 13
}
@windelknecht
Copy link
Author

It seems that none of the java.lang.* primitives work.
So is this an issue or is my code incomplete?

@eed3si9n
Copy link
Member

eed3si9n commented Feb 8, 2015

More sinister problem is that you get 0 when you unpickle.

scala> import scala.pickling._, Defaults._, json._
import scala.pickling._
import Defaults._
import json._

scala> val r1: java.lang.Byte = 13.toByte
r1: Byte = 13

scala> val r2 = r1.pickle
r2: scala.pickling.json.pickleFormat.PickleType =
JSONPickle({
  "$type": "java.lang.Byte"
})

scala> val r3 = r2.unpickle[java.lang.Byte]
r3: Byte = 0

@eed3si9n eed3si9n changed the title pickling a java.lang.Byte does not work pickling a java.lang.Byte doesn't contain value (unpickles to zero) Feb 8, 2015
@eed3si9n
Copy link
Member

eed3si9n commented Feb 8, 2015

Maybe this is a case of #60.

eed3si9n added a commit that referenced this issue Feb 9, 2015
Current implementation uses reflectivelyWithoutGetter to try accessing
primary constructor params by name, and is allowed to fail silently.
This ends up generating empty objects for Java classes like
java.lang.Byte.

- This does not attempt reflection unless we have a known param.
- When the list of fields are non-empty, but the pickler generates zero
fields, it will raise exception to fail the macro.
eed3si9n added a commit that referenced this issue Feb 10, 2015
Current implementation uses reflectivelyWithoutGetter to try accessing
primary constructor params by name, and is allowed to fail silently.
This ends up generating empty objects for Java classes like
java.lang.Byte.

- This does not attempt reflection unless we have a known param.
- When the list of fields are non-empty, but the pickler generates zero
fields, it will raise exception to fail the macro.
jsuereth added a commit that referenced this issue Feb 25, 2015
(wip) stop compiling when pickler fields are empty. Fixes #60, #263
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants