Serializing/de-serializing with different classes using Msgpack (Java API) -
i'm experimenting msgpack de-serialize object graph using msgpack hitting problems.
at moment have simple hierachy consisting of 2 classes: basemessage
, personnew
. basemessage
has single long field id
getters , setters. personnew
has string fields name
, email
, inherits basemessage
.
originally personold
class had id
field , serialized/de-serialized fine. when tring de-serialize personold
(which had id
) personnew
class (which inherits id
basemessage
) i'm being hit error:
org.msgpack.messagetypeexception: unexpected raw value
all fields i'm using private.
below sample code:
personold personold = new personold(); personold.setname("person"); personold.setemail("person@email.com"); messagepack msgpack = new messagepack(); msgpack.register(personnew.class); msgpack.register(personold.class); // serialize using old person class byte[] personbytes = msgpack.write(personold); bytearrayinputstream in = new bytearrayinputstream(personbytes); unpacker unpacker = msgpack.createunpacker(in); // deserialize using new person class personnew deserializeperson = unpacker.read(personnew.class);
the reason i'd de-serialize newer class because want see if it's possible have older serialized data (e.g. in persisted message queue) compatible newer classes (e.g. in case of class updates). have attempted use @optional
annotation on id
of basemessage
class still doesn't work.
is possible @ de-serialize different class despite having same fields?
regards,
snk
Comments
Post a Comment