I need to convert objects to a byte[] to be stored in the Tokyo Cabinet key-value store. I also need to unbyte the byte[] to an Object when reading from the key-value store.
Are there any packages out there that will help me with this task? Or would the best solution to implement it myself?
This question is related to
java
serialization
byte
bytearray
tokyo-cabinet
You can look at how Hector does this for Cassandra, where the goal is the same - convert everything to and from byte[]
in order to store/retrieve from a NoSQL database - see here. For the primitive types (+String), there are special Serializers, otherwise there is the generic ObjectSerializer
(expecting Serializable
, and using ObjectOutputStream
). You can, of course, use only it for everything, but there might be redundant meta-data in the serialized form.
I guess you can copy the entire package and make use of it.
If your class extends Serializable
, you can write and read objects through a ByteArrayOutputStream
, that's what I usually do.
Use serialize
and deserialize
methods in SerializationUtils
from commons-lang.
You can use ObjectMapper
ObjectMapper objectMapper = new ObjectMapper();
ObjectClass object = objectMapper.readValue(data, ObjectClass.class);
Source: Stackoverflow.com