Open GoogleCodeExporter opened 9 years ago
I tested against kryo 2.22.
Original comment by yangzhao...@gmail.com
on 18 Oct 2013 at 5:56
You do not provide a custom serializer for your class. Therefore Kryo tries to
guess a matching serializer. It correctly detects that your class is derived
from ArrayList. Therefore it tries to use a corresponding default collection
serializer which is able to serialize ArrayLists. The problem is that this
serializer can serialize only vanilla collection classes, without any
additional fields.
Two solve your problem, I see two possibilities:
1) You create your own serializer for your class. It can be derived from a
CollectionSerializer. Your serializer first performs super.write (super.read)
and then writes/reads your additional field. Then you register your serializer
to be used for your class.
2) You rewrite your class in such a way that it uses composition instead of
inheritance. Done this way, it would contain two fields: one field containing
an ArrayList and one field containing a name. Due to this changed structure,
Kryo would use FieldSerializer for it and perform serialization properly.
I hope these suggestions help you to solve your problem.
Original comment by romixlev
on 18 Oct 2013 at 7:33
Original issue reported on code.google.com by
yangzhao...@gmail.com
on 18 Oct 2013 at 5:46