Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing ZonedDateTime with ZoneOffset.UTC results in invalid ZoneOffset #251

Open
YuvalItzchakov opened this issue Mar 17, 2016 · 6 comments

Comments

@YuvalItzchakov
Copy link

I'm using Kryo 2.21 on Java8 with Scala 2.10.6. Kryo comes packaged along with Apache Spark.

As part of an object I'm trying to serialize, I have a ZonedDateTime which I'm trying to serialize/deserialize. When I do so, the Z part of the offset is replaced with null.

Reproduce:

import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.time.{ZoneOffset, ZonedDateTime}
import com.esotericsoftware.kryo.io.{Input, Output}
import com.twitter.chill.ScalaKryoInstantiator

object X {
  val dt = ZonedDateTime.now(ZoneOffset.UTC)

  val kryo = new ScalaKryoInstantiator().setRegistrationRequired(false).newKryo()
  val stream = new ByteArrayOutputStream()
  val output = new Output(stream)
  kryo.writeObject(output, dt)
 output.close()

  val inputStream = new ByteArrayInputStream(stream.toByteArray)
  val input = new Input(inputStream)
  kryo.readObject(input, classOf[ZonedDateTime])
}

Yields:

res2: java.time.ZonedDateTime = 2016-03-17T14:39:48.117null
@YuvalItzchakov YuvalItzchakov changed the title Serializing ZonedDateTime with ZoneOffset.UTC results in invalid toString Serializing ZonedDateTime with ZoneOffset.UTC results in invalid ZoneOffset Mar 17, 2016
@johnynek
Copy link
Collaborator

I assume that the problem here is that in that class the ZoneOffset is transient.

The only solution is to implement a serializer for this class or to change to a different class that represents the data in a way that works with kryo (a case class of primitives?)

@YuvalItzchakov
Copy link
Author

Yes, that's what I ended up doing. I can post it here if it helps anyone.

@johnynek
Copy link
Collaborator

yeah a PR to chill-java would be great (should be in java though. :/)

@modelga
Copy link

modelga commented Dec 14, 2016

@YuvalItzchakov Could you post it/made pull request into chill with that one serializer? Thanks

@magro
Copy link

magro commented Dec 17, 2016

Btw, kryo 4 already provides serializers for java.time classes.

@johnynek
Copy link
Collaborator

johnynek commented Jan 3, 2017

@YuvalItzchakov any chance you can post the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants