Nov11 / kryo

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

Suggestion: add new default Serializers for Calendar and TimeZone #71

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm starting loving Kryo as I do with ReflectASM!!

It is a good practice for some applications not to store/use java.util.Date in 
data structures and comparisons, but using java.util.Calendar instead. At least 
my applications do.

I propose to add these two serializers as defaults for Calendar and TimeZone.

See the attachments with my implementation proposals (the attachment hasn't any 
package name, copyright, etc), they could be nested classes of 
com.esotericsoftware.kryo.serializers.DefaultSerializers.

The CalendarSerializer is compatible with both java.util.GregorianCalendar, 
java.util.JapaneseImperialCalendar, sun.util.BuddhistCalendar. With the only 
limitation that the default Locale/Calendar must be the same when writting and 
when reading. I suppouse it could be made more robust...

The TimeZoneSerializer assumes the immutabilitiy of TimeZone instances (it 
doesn't have to, strictly).

Regards, 
Jesus

Original issue reported on code.google.com by serverpe...@gmail.com on 18 Jun 2012 at 12:29

Attachments:

GoogleCodeExporter commented 8 years ago
I forgot to remark the credits: the CalendarSerializer was initially inspired 
in Martin Grotzke's one, although with a different approach as you cas see.

Hope there is no problem with the credits for my proposal of adding them as 
default serializers...

Original comment by serverpe...@gmail.com on 18 Jun 2012 at 1:04

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r298.

Original comment by nathan.s...@gmail.com on 18 Jun 2012 at 1:05

GoogleCodeExporter commented 8 years ago
Always fantastic to have contributions, thanks! :) I added a test as well.

Original comment by nathan.s...@gmail.com on 18 Jun 2012 at 1:06

GoogleCodeExporter commented 8 years ago
I've downloaded the current version from Subversion (revision 300) and the 
TestCase fails to me with this message:

Testcase: testCalendar(com.esotericsoftware.kryo.DefaultSerializersTest):   FAILED
Incorrect number of bytes read. expected:<64> but was:<57>
junit.framework.AssertionFailedError: Incorrect number of bytes read. 
expected:<64> but was:<57>
    at com.esotericsoftware.kryo.KryoTestCase.roundTrip(KryoTestCase.java:47)
    at com.esotericsoftware.kryo.DefaultSerializersTest.testCalendar(DefaultSerializersTest.java:202)

Did I made something wrong?

By the way, this other Test is also failing:

Testcase: 
testInstantiatorStrategy(com.esotericsoftware.kryo.FieldSerializerTest):    Caused 
an ERROR
com.esotericsoftware.kryo.FieldSerializerTest$HasArgumentConstructor: method 
<init>()V not found
java.lang.NoSuchMethodError: 
com.esotericsoftware.kryo.FieldSerializerTest$HasArgumentConstructor: method 
<init>()V not found
    at com.esotericsoftware.kryo.FieldSerializerTest$HasArgumentConstructorConstructorAccess.newInstance(Unknown Source)
    at com.esotericsoftware.kryo.Kryo$1.newInstance(Kryo.java:967)
    at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1016)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.create(FieldSerializer.java:216)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:220)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:711)
    at com.esotericsoftware.kryo.KryoTestCase.roundTrip(KryoTestCase.java:45)
    at com.esotericsoftware.kryo.FieldSerializerTest.testInstantiatorStrategy(FieldSerializerTest.java:308)

Regards

Original comment by serverpe...@gmail.com on 18 Jun 2012 at 8:30

GoogleCodeExporter commented 8 years ago
Yeah the calendar test was using my timezone so it worked for me. Fixed.

FieldSerializer, not sure at the moment as I have it all dismantled thanks to 
your other issue. :p

Original comment by nathan.s...@gmail.com on 18 Jun 2012 at 8:34

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
:-D

Original comment by serverpe...@gmail.com on 18 Jun 2012 at 8:53