Nov11 / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Serialization of java.sql.Timestamp #88

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an object / class with a reference field to java.sql.Timestamp
2. Serialize it with Kryo
3. Deserialize it with Kryo

What is the expected output? What do you see instead?

The object should be deserialized correctly. The deserialization process 
crashes while setting the Timestamp field.

What version of the Kryo are you using?

2.20

Please provide any additional information below.

While serializing, the Date default serializer is used because the Timestamp 
class inherits from Date. The deserializer tries to put the Date class in the 
Timestamp field which leads to an IllegalArgumentException in the Field.set 
method.

A possible fix would be adding a default serializer for Timestamp or only 
applying the serializers when the class matches exactly

Original issue reported on code.google.com by selene.f...@artemicode.de on 6 Sep 2012 at 7:04

GoogleCodeExporter commented 8 years ago
Pretty much a straight copy of the DateSerializer.

  static public class TimestampSerializer extends Serializer<Timestamp> {
    public void write(Kryo kryo, Output output, Timestamp object) {
      output.writeLong(object.getTime(), true);
    }

    public Timestamp read(Kryo kryo, Input input, Class<Timestamp> type) {
      return new Timestamp(input.readLong(true));
    }

    public Timestamp copy(Kryo kryo, Timestamp original) {
      return new Timestamp(original.getTime());
    }
  }

Then you just register it.

    kryo.addDefaultSerializer(Timestamp.class, TimestampSerializer.class);

Original comment by jonathan...@gmail.com on 22 Jan 2013 at 10:42

GoogleCodeExporter commented 8 years ago
Hello. Has this issue been resolved? I've just got this exact issue in my app.

Original comment by ngocdaot...@gmail.com on 21 Mar 2013 at 9:23

GoogleCodeExporter commented 8 years ago
I'm observing a similar issue with Joda time's LocalDate class.  Not in 
Cascalog specifically (the below link), but in the combination of Spark, Kryo, 
and Joda time.

https://groups.google.com/forum/#!topic/cascalog-user/35cdnNIamKU

Original comment by Ash...@gmail.com on 24 Apr 2013 at 7:57

GoogleCodeExporter commented 8 years ago
Issues have been moved to github, this one is now 
https://github.com/EsotericSoftware/kryo/issues/88, can we proceed there?

Original comment by martin.grotzke on 13 Nov 2013 at 11:26